UCommon
|
A container for generic and o/s portable threadsafe file system functions. More...
#include <fsys.h>
Public Types | |
enum | access_t { ACCESS_RDONLY, ACCESS_WRONLY, ACCESS_REWRITE, ACCESS_RDWR = ACCESS_REWRITE, ACCESS_APPEND, ACCESS_SHARED, ACCESS_DIRECTORY, ACCESS_STREAM, ACCESS_RANDOM } |
Enumerated file access modes. | |
typedef struct stat | fileinfo_t |
typedef long | offset_t |
File offset type. | |
Public Member Functions | |
void | assign (fd_t descriptor) |
Assign descriptor directly. | |
void | close (void) |
Close a fsys resource. | |
void | create (const char *path, access_t access, unsigned mode) |
Open a file descriptor directly. | |
int | drop (offset_t size=0) |
Drop cached data from start of file. | |
int | err (void) const |
Get last error. | |
int | fileinfo (fileinfo_t *buffer) |
Get status of open descriptor. | |
fsys (fd_t handle) | |
Contruct fsys from raw file handle. | |
fsys (const char *path, access_t access) | |
Create a fsys descriptor by opening an existing file or directory. | |
fsys () | |
Construct an unattached fsys descriptor. | |
fsys (const char *path, access_t access, unsigned permission) | |
Create a fsys descriptor by creating a file. | |
fsys (const fsys &descriptor) | |
Copy (dup) an existing fsys descriptor. | |
fd_t | getHandle (void) const |
Get the native system descriptor handle of the file descriptor. | |
bool | istty (void) |
See if current file stream is a tty device. | |
void | open (const char *path, access_t access) |
Open a file or directory. | |
operator bool () const | |
Test if file descriptor is open. | |
operator fd_t () const | |
Get the descriptor from the object by casting reference. | |
bool | operator! () const |
Test if file descriptor is closed. | |
fd_t | operator* () const |
Get the descriptor from the object by pointer reference. | |
void | operator= (const fsys &descriptor) |
Assign file descriptor by duplicating another descriptor. | |
void | operator= (fd_t descriptor) |
Assing file descriptor from system descriptor. | |
ssize_t | read (void *buffer, size_t count) |
Read data from descriptor or scan directory. | |
fd_t | release (void) |
Release descriptor, do not close. | |
int | seek (offset_t offset) |
Set the position of a file descriptor. | |
void | set (fd_t descriptor) |
Set with external descriptor. | |
int | sync (void) |
Commit changes to the filesystem. | |
int | trunc (offset_t offset) |
Truncate file to specified length. | |
ssize_t | write (const void *buffer, size_t count) |
Write data to descriptor. | |
~fsys () | |
Close and release a file descriptor. | |
Static Public Member Functions | |
static int | access (const char *path, unsigned mode) |
Test path access. | |
static void | assign (fsys &object, fd_t descriptor) |
Assign a descriptor directly. | |
static int | change (const char *path, unsigned mode) |
Change file access mode. | |
static int | changeDir (const char *path) |
Set directory prefix (chdir). | |
static void | close (fsys &descriptor) |
Close a file descriptor or directory directly. | |
static int | copy (const char *source, const char *target, size_t size=1024) |
Copy a file. | |
static void | create (fsys &object, const char *path, access_t access, unsigned mode) |
create a file descriptor or directory directly. | |
static int | createDir (const char *path, unsigned mode) |
Simple direct method to create a directory. | |
static int | drop (fsys &descriptor, offset_t size) |
Drop cached data from a file descriptor. | |
static int | fileinfo (const char *path, fileinfo_t *buffer) |
Stat a file. | |
static void * | find (fsys &module, const char *symbol) |
Find symbol in loaded module. | |
static int | getPrefix (char *path, size_t size) |
Get current directory prefix (pwd). | |
static int | hardlink (const char *path, const char *target) |
Create a hard link. | |
static bool | ischar (struct stat *inode) |
static bool | isdev (struct stat *inode) |
static bool | isdir (struct stat *inode) |
static bool | isdir (const char *path) |
Test if path is a directory. | |
static bool | isdisk (struct stat *inode) |
static bool | isfile (struct stat *inode) |
static bool | isfile (const char *path) |
Test if path is a file. | |
static bool | ishidden (const char *path) |
Test if path is a hidden file. | |
static bool | islink (const char *path) |
Test if path is a symlink. | |
static bool | islink (struct stat *inode) |
static bool | issys (struct stat *inode) |
static bool | istty (fd_t fd) |
See if the file handle is a tty device. | |
static int | link (const char *path, const char *target) |
Create a symbolic link. | |
static int | linkinfo (const char *path, char *buffer, size_t size) |
Read a symbolic link to get it's target. | |
static int | load (const char *path) |
Load an unmaged plugin directly. | |
static void | load (fsys &module, const char *path) |
Load a plugin into memory. | |
static void | open (fsys &object, const char *path, access_t access) |
Open a file or directory. | |
static ssize_t | read (fsys &descriptor, void *buffer, size_t count) |
Read data from file descriptor or directory. | |
static int | remapError (void) |
static int | remove (const char *path) |
Remove a file. | |
static int | removeDir (const char *path) |
Simple direct method to remove a directory. | |
static int | rename (const char *oldpath, const char *newpath) |
Rename a file. | |
static int | seek (fsys &descriptor, offset_t offset) |
Set the position of a file descriptor. | |
static int | unlink (const char *path) |
Remove a symbolic link explicitly. | |
static void | unload (fsys &module) |
unload a specific plugin. | |
static ssize_t | write (fsys &descriptor, const void *buffer, size_t count) |
write data to file descriptor. | |
Static Public Attributes | |
static const offset_t | end |
Used to mark "append" in set position operations. | |
Protected Attributes | |
int | error |
fd_t | fd |
void * | ptr |
A container for generic and o/s portable threadsafe file system functions.
These are based roughly on their posix equivilents. For libpth, the system calls are wrapped. The native file descriptor or handle may be used, but it is best to use "class fsys" instead because it can capture the errno of a file operation in a threadsafe and platform independent manner, including for mswindows targets.
ucommon::fsys::fsys | ( | const fsys & | descriptor | ) |
Copy (dup) an existing fsys descriptor.
descriptor | to copy from. |
ucommon::fsys::fsys | ( | const char * | path, |
access_t | access | ||
) |
Create a fsys descriptor by opening an existing file or directory.
path | of file to open for created descriptor. |
access | mode of file. |
ucommon::fsys::fsys | ( | const char * | path, |
access_t | access, | ||
unsigned | permission | ||
) |
Create a fsys descriptor by creating a file.
path | of file to create for descriptor. |
access | mode of file access. |
permission | mode of file. |
static int ucommon::fsys::access | ( | const char * | path, |
unsigned | mode | ||
) | [static] |
Test path access.
path | to test. |
mode | to test for. |
void ucommon::fsys::assign | ( | fd_t | descriptor | ) | [inline] |
static void ucommon::fsys::assign | ( | fsys & | object, |
fd_t | descriptor | ||
) | [inline, static] |
static int ucommon::fsys::change | ( | const char * | path, |
unsigned | mode | ||
) | [static] |
Change file access mode.
path | to change. |
mode | to assign. |
static int ucommon::fsys::changeDir | ( | const char * | path | ) | [static] |
Set directory prefix (chdir).
path | to change to. |
static void ucommon::fsys::close | ( | fsys & | descriptor | ) | [inline, static] |
static int ucommon::fsys::copy | ( | const char * | source, |
const char * | target, | ||
size_t | size = 1024 |
||
) | [static] |
Copy a file.
source | file. |
target | file. |
size | of buffer. |
void ucommon::fsys::create | ( | const char * | path, |
access_t | access, | ||
unsigned | mode | ||
) |
Open a file descriptor directly.
path | of file to create. |
access | mode of descriptor. |
mode | of file if created. |
static int ucommon::fsys::createDir | ( | const char * | path, |
unsigned | mode | ||
) | [static] |
Simple direct method to create a directory.
path | of directory to create. |
mode | of directory. |
int ucommon::fsys::drop | ( | offset_t | size = 0 | ) |
Drop cached data from start of file.
size | of region to drop or until end of file. |
int ucommon::fsys::err | ( | void | ) | const [inline] |
int ucommon::fsys::fileinfo | ( | fileinfo_t * | buffer | ) |
Get status of open descriptor.
buffer | to save status info in. |
static int ucommon::fsys::fileinfo | ( | const char * | path, |
fileinfo_t * | buffer | ||
) | [static] |
Stat a file.
path | of file to stat. |
buffer | to save stat info. |
static void* ucommon::fsys::find | ( | fsys & | module, |
const char * | symbol | ||
) | [static] |
Find symbol in loaded module.
module | to search. |
symbol | to search for. |
fd_t ucommon::fsys::getHandle | ( | void | ) | const [inline] |
static int ucommon::fsys::getPrefix | ( | char * | path, |
size_t | size | ||
) | [static] |
Get current directory prefix (pwd).
path | to save directory into. |
size | of path we can save. |
static int ucommon::fsys::hardlink | ( | const char * | path, |
const char * | target | ||
) | [static] |
Create a hard link.
path | to create link to. |
target | of link. |
static bool ucommon::fsys::isdir | ( | const char * | path | ) | [static] |
Test if path is a directory.
path | to test. |
static bool ucommon::fsys::isfile | ( | const char * | path | ) | [static] |
Test if path is a file.
path | to test. |
static bool ucommon::fsys::ishidden | ( | const char * | path | ) | [static] |
Test if path is a hidden file.
path | to test. |
static bool ucommon::fsys::islink | ( | const char * | path | ) | [static] |
Test if path is a symlink.
path | to test. |
bool ucommon::fsys::istty | ( | void | ) |
See if current file stream is a tty device.
static bool ucommon::fsys::istty | ( | fd_t | fd | ) | [static] |
See if the file handle is a tty device.
static int ucommon::fsys::link | ( | const char * | path, |
const char * | target | ||
) | [static] |
Create a symbolic link.
path | to create. |
target | of link. |
static int ucommon::fsys::linkinfo | ( | const char * | path, |
char * | buffer, | ||
size_t | size | ||
) | [static] |
Read a symbolic link to get it's target.
path | of link. |
buffer | to save target into. |
size | of buffer. |
static int ucommon::fsys::load | ( | const char * | path | ) | [static] |
Load an unmaged plugin directly.
path | to plugin. |
static void ucommon::fsys::load | ( | fsys & | module, |
const char * | path | ||
) | [static] |
Load a plugin into memory.
module | for management. |
path | to plugin. |
void ucommon::fsys::open | ( | const char * | path, |
access_t | access | ||
) |
Open a file or directory.
path | of file to open. |
access | mode of descriptor. |
ucommon::fsys::operator bool | ( | ) | const [inline] |
ucommon::fsys::operator fd_t | ( | ) | const [inline] |
bool ucommon::fsys::operator! | ( | ) | const [inline] |
fd_t ucommon::fsys::operator* | ( | ) | const [inline] |
void ucommon::fsys::operator= | ( | const fsys & | descriptor | ) |
Assign file descriptor by duplicating another descriptor.
descriptor | to dup from. |
void ucommon::fsys::operator= | ( | fd_t | descriptor | ) |
Assing file descriptor from system descriptor.
descriptor | to dup from. |
static ssize_t ucommon::fsys::read | ( | fsys & | descriptor, |
void * | buffer, | ||
size_t | count | ||
) | [inline, static] |
ssize_t ucommon::fsys::read | ( | void * | buffer, |
size_t | count | ||
) |
Read data from descriptor or scan directory.
buffer | to read into. |
count | of bytes to read. |
fd_t ucommon::fsys::release | ( | void | ) |
Release descriptor, do not close.
static int ucommon::fsys::remove | ( | const char * | path | ) | [static] |
Remove a file.
path | of file. |
static int ucommon::fsys::removeDir | ( | const char * | path | ) | [static] |
Simple direct method to remove a directory.
path | to remove. |
static int ucommon::fsys::rename | ( | const char * | oldpath, |
const char * | newpath | ||
) | [static] |
Rename a file.
oldpath | to rename from. |
newpath | to rename to. |
int ucommon::fsys::seek | ( | offset_t | offset | ) |
Set the position of a file descriptor.
offset | from start of file or "end" to append. |
Reimplemented in ucommon::fbuf.
void ucommon::fsys::set | ( | fd_t | descriptor | ) |
Set with external descriptor.
Closes existing file if open.
descriptor | of open file. |
int ucommon::fsys::sync | ( | void | ) |
Commit changes to the filesystem.
int ucommon::fsys::trunc | ( | offset_t | offset | ) |
Truncate file to specified length.
The file pointer is positioned to the new end of file.
offset | to truncate to. |
Reimplemented in ucommon::fbuf.
static int ucommon::fsys::unlink | ( | const char * | path | ) | [static] |
Remove a symbolic link explicitly.
Other kinds of files are also deleted. This should be used when uncertain about symlinks requiring special support.
path | to remove. |
static void ucommon::fsys::unload | ( | fsys & | module | ) | [static] |
unload a specific plugin.
module | to unload |
static ssize_t ucommon::fsys::write | ( | fsys & | descriptor, |
const void * | buffer, | ||
size_t | count | ||
) | [inline, static] |
ssize_t ucommon::fsys::write | ( | const void * | buffer, |
size_t | count | ||
) |
Write data to descriptor.
buffer | to write from. |
count | of bytes to write. |