Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes

ucc::fsys Class Reference

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

#include <fsys.h>

Inheritance diagram for ucc::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 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.
 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.
 fsys ()
 Construct an unattached fsys descriptor.
 fsys (const char *path, access_t access)
 Create a fsys descriptor by opening an existing file or directory.
int getError (void) const
 Get the error number (errno) associated with the descriptor from the last error event from an opened file.
fd_t getHandle (void) const
 Get the native system descriptor handle of the file descriptor.
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= (fd_t descriptor)
 Assing file descriptor from system descriptor.
void operator= (const fsys &descriptor)
 Assign file descriptor by duplicating another descriptor.
ssize_t read (void *buffer, size_t count)
 Read data from descriptor or scan directory.
int seek (offset_t offset)
 Set the position of a file descriptor.
int stat (struct stat *buffer)
 Get status of open 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 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 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 bool isdir (const char *path)
 Test if path is a directory.
static bool isfile (const char *path)
 Test if path is a file.
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 size_t printf (FILE *file, const char *format,...)
 A convenience method to standardize file printf.
static ssize_t read (fsys &descriptor, void *buffer, size_t count)
 Read data from file descriptor or directory.
static size_t readln (FILE *file, char *address, size_t size)
 A realine method for files.
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 stat (const char *path, struct stat *buffer)
 Stat a file.
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 size_t writes (FILE *file, const char *string)
 A convenience method to standardize writing strings.

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

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 65 of file fsys.h.


Constructor & Destructor Documentation

ucc::fsys::fsys ( const fsys descriptor  ) 

Copy (dup) an existing fsys descriptor.

Parameters:
descriptor to copy from.
ucc::fsys::fsys ( const char *  path,
access_t  access 
)

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

Parameters:
path of file to open for created descriptor.
access mode of file.
ucc::fsys::fsys ( const char *  path,
access_t  access,
unsigned  permission 
)

Create a fsys descriptor by creating a file.

Parameters:
path of file to create for descriptor.
access mode of file access.
permission mode of file.

Member Function Documentation

static int ucc::fsys::access ( const char *  path,
unsigned  mode 
) [static]

Test path access.

Parameters:
path to test.
mode to test for.
Returns:
error number or 0 on success.
static void ucc::fsys::assign ( fsys object,
fd_t  descriptor 
) [inline, static]

Assign a descriptor directly.

Parameters:
object to assign descriptor to.
descriptor to assign.

Definition at line 373 of file fsys.h.

void ucc::fsys::assign ( fd_t  descriptor  )  [inline]

Assign descriptor directly.

Parameters:
descriptor to assign.

Definition at line 365 of file fsys.h.

static int ucc::fsys::change ( const char *  path,
unsigned  mode 
) [static]

Change file access mode.

Parameters:
path to change.
mode to assign.
Returns:
error number or 0 on success.
static int ucc::fsys::changeDir ( const char *  path  )  [static]

Set directory prefix (chdir).

Parameters:
path to change to.
Returns:
error number or 0 on success.
static void ucc::fsys::close ( fsys descriptor  )  [inline, static]

Close a file descriptor or directory directly.

Parameters:
descriptor to close.

Definition at line 403 of file fsys.h.

Here is the call graph for this function:

void ucc::fsys::create ( const char *  path,
access_t  access,
unsigned  mode 
)

Open a file descriptor directly.

Parameters:
path of file to create.
access mode of descriptor.
mode of file if created.
static void ucc::fsys::create ( fsys object,
const char *  path,
access_t  access,
unsigned  mode 
) [inline, static]

create a file descriptor or directory directly.

Parameters:
object to assign descriptor for created file.
path of file to create.
access mode of descriptor.
mode of file if created.

Definition at line 427 of file fsys.h.

static int ucc::fsys::createDir ( const char *  path,
unsigned  mode 
) [static]

Simple direct method to create a directory.

Parameters:
path of directory to create.
mode of directory.
Returns:
error number or 0 on success.
int ucc::fsys::drop ( offset_t  size = 0  ) 

Drop cached data from start of file.

Parameters:
size of region to drop or until end of file.
Returns:
error number or 0 on success.
static int ucc::fsys::drop ( fsys descriptor,
offset_t  size 
) [inline, static]

Drop cached data from a file descriptor.

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

Definition at line 351 of file fsys.h.

Here is the call graph for this function:

static void* ucc::fsys::find ( fsys module,
const char *  symbol 
) [static]

Find symbol in loaded module.

Parameters:
module to search.
symbol to search for.
Returns:
address of symbol or NULL if not found.
int ucc::fsys::getError ( void   )  const [inline]

Get the error number (errno) associated with the descriptor from the last error event from an opened file.

Returns:
error number.

Definition at line 186 of file fsys.h.

fd_t ucc::fsys::getHandle ( void   )  const [inline]

Get the native system descriptor handle of the file descriptor.

Returns:
native os descriptor.

Definition at line 193 of file fsys.h.

static int ucc::fsys::getPrefix ( char *  path,
size_t  size 
) [static]

Get current directory prefix (pwd).

Parameters:
path to save directory into.
size of path we can save.
Returns:
error number or 0 on success.
static bool ucc::fsys::isdir ( const char *  path  )  [static]

Test if path is a directory.

Parameters:
path to test.
Returns:
true if exists and is directory.
static bool ucc::fsys::isfile ( const char *  path  )  [static]

Test if path is a file.

Parameters:
path to test.
Returns:
true if exists and is file.
static void ucc::fsys::load ( fsys module,
const char *  path 
) [static]

Load a plugin into memory.

Parameters:
module for management.
path to plugin.
static int ucc::fsys::load ( const char *  path  )  [static]

Load an unmaged plugin directly.

Parameters:
path to plugin.
Returns:
error number or 0 on success.
static void ucc::fsys::open ( fsys object,
const char *  path,
access_t  access 
) [inline, static]

Open a file or directory.

Parameters:
object to assign descriptor for opened file.
path of file to open.
access mode of descriptor.

Definition at line 417 of file fsys.h.

void ucc::fsys::open ( const char *  path,
access_t  access 
)

Open a file or directory.

Parameters:
path of file to open.
access mode of descriptor.
ucc::fsys::operator bool (  )  const [inline]

Test if file descriptor is open.

Returns:
true if open.

Definition at line 159 of file fsys.h.

ucc::fsys::operator fd_t (  )  const [inline]

Get the descriptor from the object by casting reference.

Returns:
low level file handle.

Definition at line 152 of file fsys.h.

bool ucc::fsys::operator! (  )  const [inline]

Test if file descriptor is closed.

Returns:
true if closed.

Definition at line 166 of file fsys.h.

fd_t ucc::fsys::operator* (  )  const [inline]

Get the descriptor from the object by pointer reference.

Returns:
low level file handle.

Definition at line 145 of file fsys.h.

void ucc::fsys::operator= ( const fsys descriptor  ) 

Assign file descriptor by duplicating another descriptor.

Parameters:
descriptor to dup from.
void ucc::fsys::operator= ( fd_t  descriptor  ) 

Assing file descriptor from system descriptor.

Parameters:
descriptor to dup from.
static size_t ucc::fsys::printf ( FILE *  file,
const char *  format,
  ... 
) [static]

A convenience method to standardize file printf.

This mostly is to assure some consistency in coding practices and return values.

Parameters:
file to write to.
format of printf string.
Returns:
number of bytes written.
ssize_t ucc::fsys::read ( void *  buffer,
size_t  count 
)

Read data from descriptor or scan directory.

Parameters:
buffer to read into.
count of bytes to read.
Returns:
bytes transferred, -1 if error.
static ssize_t ucc::fsys::read ( fsys descriptor,
void *  buffer,
size_t  count 
) [inline, static]

Read data from file descriptor or directory.

Parameters:
descriptor to read from.
buffer to read into.
count of bytes to read.
Returns:
bytes transferred, -1 if error.

Definition at line 323 of file fsys.h.

Here is the call graph for this function:

static size_t ucc::fsys::readln ( FILE *  file,
char *  address,
size_t  size 
) [static]

A realine method for files.

This is mostly to offer behavior similar to other readln methods, which can accept either "\n" or "\r\n" line termination, and strip the eol from the buffer.

Parameters:
file to read from.
address of buffer to save string.
size of buffer.
Returns:
number of bytes actually retrieved. 0 may indicate EOF.
static int ucc::fsys::remove ( const char *  path  )  [static]

Remove a file.

Parameters:
path of file.
Returns:
error number or 0 on success.
static int ucc::fsys::removeDir ( const char *  path  )  [static]

Simple direct method to remove a directory.

Parameters:
path to remove.
Returns:
error number or 0 on success.
static int ucc::fsys::rename ( const char *  oldpath,
const char *  newpath 
) [static]

Rename a file.

Parameters:
oldpath to rename from.
newpath to rename to.
Returns:
error number or 0 on success.
int ucc::fsys::seek ( offset_t  offset  ) 

Set the position of a file descriptor.

Parameters:
offset from start of file or "end" to append.
Returns:
error number or 0 on success.
static int ucc::fsys::seek ( fsys descriptor,
offset_t  offset 
) [inline, static]

Set the position of a file descriptor.

Parameters:
descriptor to set.
offset from start of file or "end" to append.
Returns:
error number or 0 on success.

Definition at line 342 of file fsys.h.

Here is the call graph for this function:

static int ucc::fsys::stat ( const char *  path,
struct stat *  buffer 
) [static]

Stat a file.

Parameters:
path of file to stat.
buffer to save stat info.
Returns:
error number or 0 on success.
int ucc::fsys::stat ( struct stat *  buffer  ) 

Get status of open descriptor.

Parameters:
buffer to save status info in.
Returns:
error number or 0 on success.
int ucc::fsys::sync ( void   ) 

Commit changes to the filesystem.

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

Truncate file to specified length.

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

Parameters:
offset to truncate to.
Returns:
true if truncate successful.
static void ucc::fsys::unload ( fsys module  )  [static]

unload a specific plugin.

Parameters:
module to unload
ssize_t ucc::fsys::write ( const void *  buffer,
size_t  count 
)

Write data to descriptor.

Parameters:
buffer to write from.
count of bytes to write.
Returns:
bytes transferred, -1 if error.
static ssize_t ucc::fsys::write ( fsys descriptor,
const void *  buffer,
size_t  count 
) [inline, static]

write data to file descriptor.

Parameters:
descriptor to write to.
buffer to write from.
count of bytes to write.
Returns:
bytes transferred, -1 if error.

Definition at line 333 of file fsys.h.

Here is the call graph for this function:

static size_t ucc::fsys::writes ( FILE *  file,
const char *  string 
) [static]

A convenience method to standardize writing strings.

This is mostly to assure some consistency with other common code.

Parameters:
file to write to.
string to write.
Returns:
number of bytes written.

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