UCommon
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes
ucommon::fsys Class Reference

A container for generic and o/s portable threadsafe file system functions. More...

#include <fsys.h>

Inheritance diagram for ucommon::fsys:
Inheritance graph
[legend]

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 (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)
 Get last error.
int fileinfo (fileinfo_t *buffer)
 Get status of open descriptor.
 fsys ()
 Construct an unattached fsys descriptor.
 fsys (fd_t handle)
 Contruct fsys from raw file handle.
 fsys (fsys &descriptor)
 Copy (dup) an existing fsys descriptor.
 fsys (char *path, access_t access)
 Create a fsys descriptor by opening an existing file or directory.
 fsys (char *path, access_t access, unsigned permission)
 Create a fsys descriptor by creating a file.
fd_t getHandle (void)
 Get the native system descriptor handle of the file descriptor.
bool istty (void)
 See if current file stream is a tty device.
void open (char *path, access_t access)
 Open a file or directory.
 operator bool ()
 Test if file descriptor is open.
 operator fd_t ()
 Get the descriptor from the object by casting reference.
bool operator! ()
 Test if file descriptor is closed.
fd_t operator* ()
 Get the descriptor from the object by pointer reference.
void operator= (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 (void *buffer, size_t count)
 Write data to descriptor.
 ~fsys ()
 Close and release a file descriptor.

Static Public Member Functions

static int access (char *path, unsigned mode)
 Test path access.
static fd_t append (char *path)
 Direct means to create or append a writable path and return descriptor.
static void assign (fsys &object, fd_t descriptor)
 Assign a descriptor directly.
static int change (char *path, unsigned mode)
 Change file access mode.
static int changeDir (char *path)
 Set directory prefix (chdir).
static void close (fsys &descriptor)
 Close a file descriptor or directory directly.
static int copy (char *source, char *target, size_t size=1024)
 Copy a file.
static void create (fsys &object, char *path, access_t access, unsigned mode)
 create a file descriptor or directory directly.
static int createDir (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 (char *path, fileinfo_t *buffer)
 Stat a file.
static void * find (fsys &module, char *symbol)
 Find symbol in loaded module.
static int getPrefix (char *path, size_t size)
 Get current directory prefix (pwd).
static int hardlink (char *path, char *target)
 Create a hard link.
static fd_t input (char *path)
 Direct means to open a read-only file path and return a descriptor.
static bool ischar (struct stat *inode)
static bool isdev (struct stat *inode)
static bool isdir (char *path)
 Test if path is a directory.
static bool isdir (struct stat *inode)
static bool isdisk (struct stat *inode)
static bool isfile (char *path)
 Test if path is a file.
static bool isfile (struct stat *inode)
static bool ishidden (char *path)
 Test if path is a hidden file.
static bool islink (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 (char *path, char *target)
 Create a symbolic link.
static int linkinfo (char *path, char *buffer, size_t size)
 Read a symbolic link to get it's target.
static int load (char *path)
 Load an unmaged plugin directly.
static void load (fsys &module, char *path)
 Load a plugin into memory.
static void open (fsys &object, char *path, access_t access)
 Open a file or directory.
static fd_t output (char *path)
 Direct means to create or access a writable path and return descriptor.
static ssize_t read (fsys &descriptor, void *buffer, size_t count)
 Read data from file descriptor or directory.
static void release (fd_t descriptor)
 Release a file descriptor.
static int remapError (void)
static int remove (char *path)
 Remove a file.
static int removeDir (char *path)
 Simple direct method to remove a directory.
static int rename (char *oldpath, char *newpath)
 Rename a file.
static int seek (fsys &descriptor, offset_t offset)
 Set the position of a file descriptor.
static int unlink (char *path)
 Remove a symbolic link explicitly.
static void unload (fsys &module)
 unload a specific plugin.
static ssize_t write (fsys &descriptor, void *buffer, size_t count)
 write data to file descriptor.

Static Public Attributes

static offset_t end
 Used to mark "append" in set position operations.

Protected Attributes

int error
fd_t fd
void * ptr

Detailed Description

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.

Definition at line 125 of file fsys.h.


Constructor & Destructor Documentation

ucommon::fsys::fsys ( fsys descriptor)

Copy (dup) an existing fsys descriptor.

Parameters:
descriptorto copy from.
ucommon::fsys::fsys ( char *  path,
access_t  access 
)

Create a fsys descriptor by opening an existing file or directory.

Parameters:
pathof file to open for created descriptor.
accessmode of file.
ucommon::fsys::fsys ( char *  path,
access_t  access,
unsigned  permission 
)

Create a fsys descriptor by creating a file.

Parameters:
pathof file to create for descriptor.
accessmode of file access.
permissionmode of file.

Member Function Documentation

static int ucommon::fsys::access ( char *  path,
unsigned  mode 
)
static

Test path access.

Parameters:
pathto test.
modeto test for.
Returns:
error number or 0 on success.
static fd_t ucommon::fsys::append ( char *  path)
static

Direct means to create or append a writable path and return descriptor.

Parameters:
pathto create.
Returns:
descriptor on success, invalid handle on failure.
void ucommon::fsys::assign ( fd_t  descriptor)
inline

Assign descriptor directly.

Parameters:
descriptorto assign.

Definition at line 470 of file fsys.h.

static void ucommon::fsys::assign ( fsys object,
fd_t  descriptor 
)
inlinestatic

Assign a descriptor directly.

Parameters:
objectto assign descriptor to.
descriptorto assign.

Definition at line 478 of file fsys.h.

static int ucommon::fsys::change ( char *  path,
unsigned  mode 
)
static

Change file access mode.

Parameters:
pathto change.
modeto assign.
Returns:
error number or 0 on success.
static int ucommon::fsys::changeDir ( char *  path)
static

Set directory prefix (chdir).

Parameters:
pathto change to.
Returns:
error number or 0 on success.
static void ucommon::fsys::close ( fsys descriptor)
inlinestatic

Close a file descriptor or directory directly.

Parameters:
descriptorto close.

Definition at line 541 of file fsys.h.

Here is the call graph for this function:

static int ucommon::fsys::copy ( char *  source,
char *  target,
size_t  size = 1024 
)
static

Copy a file.

Parameters:
sourcefile.
targetfile.
sizeof buffer.
Returns:
error number or 0 on success.
void ucommon::fsys::create ( char *  path,
access_t  access,
unsigned  mode 
)

Open a file descriptor directly.

Parameters:
pathof file to create.
accessmode of descriptor.
modeof file if created.
static void ucommon::fsys::create ( fsys object,
char *  path,
access_t  access,
unsigned  mode 
)
inlinestatic

create a file descriptor or directory directly.

Parameters:
objectto assign descriptor for created file.
pathof file to create.
accessmode of descriptor.
modeof file if created.

Definition at line 599 of file fsys.h.

static int ucommon::fsys::createDir ( char *  path,
unsigned  mode 
)
static

Simple direct method to create a directory.

Parameters:
pathof directory to create.
modeof directory.
Returns:
error number or 0 on success.
int ucommon::fsys::drop ( offset_t  size = 0)

Drop cached data from start of file.

Parameters:
sizeof region to drop or until end of file.
Returns:
error number or 0 on success.
static int ucommon::fsys::drop ( fsys descriptor,
offset_t  size 
)
inlinestatic

Drop cached data from a file descriptor.

Parameters:
descriptorto set.
sizeof region from start of file to drop or all.
Returns:
error number or 0 on success.

Definition at line 456 of file fsys.h.

Here is the call graph for this function:

int ucommon::fsys::err ( void  )
inline

Get last error.

Returns:
error number.

Definition at line 553 of file fsys.h.

int ucommon::fsys::fileinfo ( fileinfo_t *  buffer)

Get status of open descriptor.

Parameters:
bufferto save status info in.
Returns:
error number or 0 on success.
static int ucommon::fsys::fileinfo ( char *  path,
fileinfo_t *  buffer 
)
static

Stat a file.

Parameters:
pathof file to stat.
bufferto save stat info.
Returns:
error number or 0 on success.
static void* ucommon::fsys::find ( fsys module,
char *  symbol 
)
static

Find symbol in loaded module.

Parameters:
moduleto search.
symbolto search for.
Returns:
address of symbol or NULL if not found.
fd_t ucommon::fsys::getHandle ( void  )
inline

Get the native system descriptor handle of the file descriptor.

Returns:
native os descriptor.

Definition at line 252 of file fsys.h.

static int ucommon::fsys::getPrefix ( char *  path,
size_t  size 
)
static

Get current directory prefix (pwd).

Parameters:
pathto save directory into.
sizeof path we can save.
Returns:
error number or 0 on success.
static int ucommon::fsys::hardlink ( char *  path,
char *  target 
)
static

Create a hard link.

Parameters:
pathto create link to.
targetof link.
Returns:
error number or 0 on success.
static fd_t ucommon::fsys::input ( char *  path)
static

Direct means to open a read-only file path and return a descriptor.

Parameters:
pathto open.
Returns:
descriptor on success, invalid handle on failure.
static bool ucommon::fsys::isdir ( char *  path)
static

Test if path is a directory.

Parameters:
pathto test.
Returns:
true if exists and is directory.
static bool ucommon::fsys::isfile ( char *  path)
static

Test if path is a file.

Parameters:
pathto test.
Returns:
true if exists and is file.
static bool ucommon::fsys::ishidden ( char *  path)
static

Test if path is a hidden file.

Parameters:
pathto test.
Returns:
true if exists and is hidden.
static bool ucommon::fsys::islink ( char *  path)
static

Test if path is a symlink.

Parameters:
pathto test.
Returns:
true if exists and is symlink.
bool ucommon::fsys::istty ( void  )

See if current file stream is a tty device.

Returns:
true if device.
static bool ucommon::fsys::istty ( fd_t  fd)
static

See if the file handle is a tty device.

Returns:
true if device.
static int ucommon::fsys::link ( char *  path,
char *  target 
)
static

Create a symbolic link.

Parameters:
pathto create.
targetof link.
Returns:
error number or 0 on success.
static int ucommon::fsys::linkinfo ( char *  path,
char *  buffer,
size_t  size 
)
static

Read a symbolic link to get it's target.

Parameters:
pathof link.
bufferto save target into.
sizeof buffer.
static int ucommon::fsys::load ( char *  path)
static

Load an unmaged plugin directly.

Parameters:
pathto plugin.
Returns:
error number or 0 on success.
static void ucommon::fsys::load ( fsys module,
char *  path 
)
static

Load a plugin into memory.

Parameters:
modulefor management.
pathto plugin.
void ucommon::fsys::open ( char *  path,
access_t  access 
)

Open a file or directory.

Parameters:
pathof file to open.
accessmode of descriptor.
static void ucommon::fsys::open ( fsys object,
char *  path,
access_t  access 
)
inlinestatic

Open a file or directory.

Parameters:
objectto assign descriptor for opened file.
pathof file to open.
accessmode of descriptor.

Definition at line 562 of file fsys.h.

ucommon::fsys::operator bool ( )
inline

Test if file descriptor is open.

Returns:
true if open.

Definition at line 226 of file fsys.h.

ucommon::fsys::operator fd_t ( )
inline

Get the descriptor from the object by casting reference.

Returns:
low level file handle.

Definition at line 219 of file fsys.h.

bool ucommon::fsys::operator! ( )
inline

Test if file descriptor is closed.

Returns:
true if closed.

Definition at line 233 of file fsys.h.

fd_t ucommon::fsys::operator* ( )
inline

Get the descriptor from the object by pointer reference.

Returns:
low level file handle.

Definition at line 212 of file fsys.h.

void ucommon::fsys::operator= ( fsys descriptor)

Assign file descriptor by duplicating another descriptor.

Parameters:
descriptorto dup from.
void ucommon::fsys::operator= ( fd_t  descriptor)

Assing file descriptor from system descriptor.

Parameters:
descriptorto dup from.
static fd_t ucommon::fsys::output ( char *  path)
static

Direct means to create or access a writable path and return descriptor.

Parameters:
pathto create.
Returns:
descriptor on success, invalid handle on failure.
ssize_t ucommon::fsys::read ( void *  buffer,
size_t  count 
)

Read data from descriptor or scan directory.

Parameters:
bufferto read into.
countof bytes to read.
Returns:
bytes transferred, -1 if error.
static ssize_t ucommon::fsys::read ( fsys descriptor,
void *  buffer,
size_t  count 
)
inlinestatic

Read data from file descriptor or directory.

Parameters:
descriptorto read from.
bufferto read into.
countof bytes to read.
Returns:
bytes transferred, -1 if error.

Definition at line 428 of file fsys.h.

Here is the call graph for this function:

fd_t ucommon::fsys::release ( void  )

Release descriptor, do not close.

Returns:
handle being released.
static void ucommon::fsys::release ( fd_t  descriptor)
static

Release a file descriptor.

Parameters:
descriptorto release.
static int ucommon::fsys::remove ( char *  path)
static

Remove a file.

Parameters:
pathof file.
Returns:
error number or 0 on success.
static int ucommon::fsys::removeDir ( char *  path)
static

Simple direct method to remove a directory.

Parameters:
pathto remove.
Returns:
error number or 0 on success.
static int ucommon::fsys::rename ( char *  oldpath,
char *  newpath 
)
static

Rename a file.

Parameters:
oldpathto rename from.
newpathto rename to.
Returns:
error number or 0 on success.
int ucommon::fsys::seek ( offset_t  offset)

Set the position of a file descriptor.

Parameters:
offsetfrom start of file or "end" to append.
Returns:
error number or 0 on success.

Reimplemented in ucommon::fbuf.

static int ucommon::fsys::seek ( fsys descriptor,
offset_t  offset 
)
inlinestatic

Set the position of a file descriptor.

Parameters:
descriptorto set.
offsetfrom start of file or "end" to append.
Returns:
error number or 0 on success.

Definition at line 447 of file fsys.h.

Here is the call graph for this function:

void ucommon::fsys::set ( fd_t  descriptor)

Set with external descriptor.

Closes existing file if open.

Parameters:
descriptorof open file.
int ucommon::fsys::sync ( void  )

Commit changes to the filesystem.

Returns:
error number or 0 on success.
int ucommon::fsys::trunc ( offset_t  offset)

Truncate file to specified length.

The file pointer is positioned to the new end of file.

Parameters:
offsetto truncate to.
Returns:
true if truncate successful.

Reimplemented in ucommon::fbuf.

static int ucommon::fsys::unlink ( 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.

Parameters:
pathto remove.
Returns:
error number or 0 on success.
static void ucommon::fsys::unload ( fsys module)
static

unload a specific plugin.

Parameters:
moduleto unload
ssize_t ucommon::fsys::write ( void *  buffer,
size_t  count 
)

Write data to descriptor.

Parameters:
bufferto write from.
countof bytes to write.
Returns:
bytes transferred, -1 if error.
static ssize_t ucommon::fsys::write ( fsys descriptor,
void *  buffer,
size_t  count 
)
inlinestatic

write data to file descriptor.

Parameters:
descriptorto write to.
bufferto write from.
countof bytes to write.
Returns:
bytes transferred, -1 if error.

Definition at line 438 of file fsys.h.

Here is the call graph for this function:


The documentation for this class was generated from the following file: