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  {
  OWNER_READONLY = 0400, GROUP_READONLY = 0440, PUBLIC_READONLY = 0444, OWNER_PRIVATE = 0600,
  OWNER_PUBLIC = 0644, GROUP_PRIVATE = 0660, GROUP_PUBLIC = 0664, EVERYONE = 0666,
  DIR_TEMPORARY = 01777
}
 Most of the common chmod values are predefined.
enum  access_t {
  RDONLY, WRONLY, REWRITE, RDWR = REWRITE,
  APPEND, SHARED, EXCLUSIVE, DEVICE,
  STREAM, RANDOM
}
 Enumerated file access modes.
 APPEND
 DEVICE
 DIR_TEMPORARY = 01777
 EVERYONE = 0666
 EXCLUSIVE
typedef stat fileinfo_t
 GROUP_PRIVATE = 0660
 GROUP_PUBLIC = 0664
 GROUP_READONLY = 0440
typedef long offset_t
 File offset type.
 OWNER_PRIVATE = 0600
 OWNER_PUBLIC = 0644
 OWNER_READONLY = 0400
 PUBLIC_READONLY = 0444
 RANDOM
 RDONLY
 RDWR = REWRITE
 REWRITE
 SHARED
 STREAM
 WRONLY

Public Member Functions

void assign (fd_t descriptor)
 Assign descriptor directly.
int close (void)
 Close a fsys resource.
int drop (offset_t size=0)
 Drop cached data from start of file.
int err (void)
 Get last error.
 fsys (char *path, unsigned permission, access_t access)
 Create a fsys descriptor by creating a file.
 fsys (char *path, access_t access)
 Create a fsys descriptor by opening an existing file or directory.
 fsys (fsys &descriptor)
 Copy (dup) an existing fsys descriptor.
 fsys (fd_t handle)
 Contruct fsys from raw file handle.
 fsys ()
 Construct an unattached fsys descriptor.
fd_t handle (void)
 Get the native system descriptor handle of the file descriptor.
int info (fileinfo_t *buffer)
 Get status of open descriptor.
bool is_tty (void)
 See if current file stream is a tty device.
void open (char *path, unsigned mode, access_t access)
 Open a file descriptor directly.
void open (char *path, access_t access)
 Open a file or directory.
fd_t operator * ()
 Get the descriptor from the object by pointer reference.
void operator *= (fd_t &descriptor)
 Replace current file descriptor with an external descriptor.
 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.
void operator= (fd_t descriptor)
 Assing file descriptor from system descriptor.
void operator= (fsys &descriptor)
 Assign file descriptor by duplicating another 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.
void reset (void)
 Reset error flag.
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 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 copy (char *source, char *target, size_t size=1024)
 Copy a file.
static int erase (char *path)
 Erase (remove) a file only.
static int exec (char *path, char **argv, char **envp=((void *) 0))
 Execute a process and get exit code.
static int hardlink (char *path, char *target)
 Create a hard link.
static int info (char *path, fileinfo_t *buffer)
 Stat a file.
static int inherit (fd_t &descriptor, bool enable)
 Changle inheritable handle.
static fd_t input (char *path)
 Direct means to open a read-only file path and return a descriptor.
static bool is_char (struct stat *inode)
static bool is_dev (struct stat *inode)
static bool is_device (char *path)
 Test if path is a device path.
static bool is_dir (struct stat *inode)
static bool is_dir (char *path)
 Test if path is a directory.
static bool is_disk (struct stat *inode)
static bool is_executable (char *path)
 Test if path is executable.
static bool is_exists (char *path)
 Test if path exists.
static bool is_file (struct stat *inode)
static bool is_file (char *path)
 Test if path is a file.
static bool is_hidden (char *path)
 Test if path is a hidden file.
static bool is_link (struct stat *inode)
static bool is_link (char *path)
 Test if path is a symlink.
static bool is_readable (char *path)
 Test if path readable.
static bool is_sys (struct stat *inode)
static bool is_tty (fd_t fd)
 See if the file handle is a tty device.
static bool is_writable (char *path)
 Test if path writable.
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 a library into memory.
static int mode (char *path, unsigned value)
 Change file access mode.
static fd_t null (void)
 Create inheritable /dev/null handle.
static fd_t output (char *path)
 Direct means to create or access a writable path and return descriptor.
static int pipe (fd_t &input, fd_t &output, size_t size=0)
 Create pipe.
static string_t prefix (void)
static int prefix (char *path, size_t size)
 Get current directory prefix (pwd).
static int prefix (char *path)
 Set directory prefix (chdir).
static void release (fd_t descriptor)
 Release a file descriptor.
static int remapError (void)
static int rename (char *oldpath, char *newpath)
 Rename a file.
static int unlink (char *path)
 Remove a symbolic link explicitly.

Static Public Attributes

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

Protected Attributes

int error
fd_t fd

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


Constructor & Destructor Documentation

ucommon::fsys::fsys ( fsys descriptor  ) 

Copy (dup) an existing fsys descriptor.

Parameters:
descriptor to copy from.

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

ucommon::fsys::fsys ( char *  path,
unsigned  permission,
access_t  access 
)

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 fd_t ucommon::fsys::append ( char *  path  )  [static]

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

Parameters:
path to create.
Returns:
descriptor on success, invalid handle on failure.

static void ucommon::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 491 of file fsys.h.

References close(), and fd.

Here is the call graph for this function:

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

Assign descriptor directly.

Parameters:
descriptor to assign.

Definition at line 483 of file fsys.h.

int ucommon::fsys::close ( void   ) 

Close a fsys resource.

Returns:
error code as needed.

Reimplemented in ucommon::dir.

Referenced by assign().

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

Copy a file.

Parameters:
source file.
target file.
size of buffer.
Returns:
error number or 0 on success.

int ucommon::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 ucommon::fsys::erase ( char *  path  )  [static]

Erase (remove) a file only.

Parameters:
path of file.
Returns:
error number or 0 on success.

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

Get last error.

Returns:
error number.

Reimplemented in ucommon::dir.

Definition at line 545 of file fsys.h.

static int ucommon::fsys::exec ( char *  path,
char **  argv,
char **  envp = ((void *) 0) 
) [static]

Execute a process and get exit code.

Parameters:
path to execute.
argv list.
optional env.
Returns:
exit code.

fd_t ucommon::fsys::handle ( void   )  [inline]

Get the native system descriptor handle of the file descriptor.

Returns:
native os descriptor.

Definition at line 274 of file fsys.h.

static int ucommon::fsys::hardlink ( char *  path,
char *  target 
) [static]

Create a hard link.

Parameters:
path to create link to.
target of link.
Returns:
error number or 0 on success.

static int ucommon::fsys::info ( char *  path,
fileinfo_t buffer 
) [static]

Stat a file.

Parameters:
path of file to stat.
buffer to save stat info.
Returns:
error number or 0 on success.

int ucommon::fsys::info ( fileinfo_t buffer  ) 

Get status of open descriptor.

Parameters:
buffer to save status info in.
Returns:
error number or 0 on success.

static int ucommon::fsys::inherit ( fd_t descriptor,
bool  enable 
) [static]

Changle inheritable handle.

On windows this is done by creating a duplicate handle and then closing the original. Elsewhere this is done simply by setting flags.

Parameters:
descriptor to modify.
enable child process inheritence.
Returns:
0 on success, error on failure.

static fd_t ucommon::fsys::input ( char *  path  )  [static]

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

Parameters:
path to open.
Returns:
descriptor on success, invalid handle on failure.

static bool ucommon::fsys::is_device ( char *  path  )  [static]

Test if path is a device path.

Parameters:
path to test.
Returns:
true of is a device path.

static bool ucommon::fsys::is_dir ( char *  path  )  [static]

Test if path is a directory.

Parameters:
path to test.
Returns:
true if exists and is directory.

static bool ucommon::fsys::is_executable ( char *  path  )  [static]

Test if path is executable.

Parameters:
path to test.
Returns:
if true.

static bool ucommon::fsys::is_exists ( char *  path  )  [static]

Test if path exists.

Parameters:
path to test.
Returns:
if true.

static bool ucommon::fsys::is_file ( char *  path  )  [static]

Test if path is a file.

Parameters:
path to test.
Returns:
true if exists and is file.

static bool ucommon::fsys::is_hidden ( char *  path  )  [static]

Test if path is a hidden file.

Parameters:
path to test.
Returns:
true if exists and is hidden.

static bool ucommon::fsys::is_link ( char *  path  )  [static]

Test if path is a symlink.

Parameters:
path to test.
Returns:
true if exists and is symlink.

static bool ucommon::fsys::is_readable ( char *  path  )  [static]

Test if path readable.

Parameters:
path to test.
Returns:
if true.

static bool ucommon::fsys::is_tty ( fd_t  fd  )  [static]

See if the file handle is a tty device.

Returns:
true if device.

bool ucommon::fsys::is_tty ( void   ) 

See if current file stream is a tty device.

Returns:
true if device.

static bool ucommon::fsys::is_writable ( char *  path  )  [static]

Test if path writable.

Parameters:
path to test.
Returns:
if true.

static int ucommon::fsys::link ( char *  path,
char *  target 
) [static]

Create a symbolic link.

Parameters:
path to create.
target of 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:
path of link.
buffer to save target into.
size of buffer.

static int ucommon::fsys::load ( char *  path  )  [static]

Load a library into memory.

Parameters:
path to plugin.
Returns:
0 on success, else error.

static int ucommon::fsys::mode ( char *  path,
unsigned  value 
) [static]

Change file access mode.

Parameters:
path to change.
value of mode to assign.
Returns:
error number or 0 on success.

static fd_t ucommon::fsys::null ( void   )  [static]

Create inheritable /dev/null handle.

Returns:
null device handle.

void ucommon::fsys::open ( char *  path,
unsigned  mode,
access_t  access 
)

Open a file descriptor directly.

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

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

Open a file or directory.

Parameters:
path of file to open.
access mode of descriptor.

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

Get the descriptor from the object by pointer reference.

Returns:
low level file handle.

Definition at line 221 of file fsys.h.

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

Replace current file descriptor with an external descriptor.

This does not create a duplicate. The external descriptor object is marked as invalid.

ucommon::fsys::operator bool (  )  [inline]

Test if file descriptor is open.

Returns:
true if open.

Reimplemented in ucommon::dir.

Definition at line 241 of file fsys.h.

References INVALID_HANDLE_VALUE.

ucommon::fsys::operator fd_t (  )  [inline]

Get the descriptor from the object by casting reference.

Returns:
low level file handle.

Definition at line 228 of file fsys.h.

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

Test if file descriptor is closed.

Returns:
true if closed.

Reimplemented in ucommon::dir.

Definition at line 248 of file fsys.h.

References INVALID_HANDLE_VALUE.

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

Assing file descriptor from system descriptor.

Parameters:
descriptor to dup from.

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

Assign file descriptor by duplicating another descriptor.

Parameters:
descriptor to dup from.

static fd_t ucommon::fsys::output ( char *  path  )  [static]

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

Parameters:
path to create.
Returns:
descriptor on success, invalid handle on failure.

static int ucommon::fsys::pipe ( fd_t input,
fd_t output,
size_t  size = 0 
) [static]

Create pipe.

These are created inheritable by default.

Parameters:
input descriptor.
output descriptor.
size of buffer if supported.
Returns:
0 or error code.

static int ucommon::fsys::prefix ( 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 int ucommon::fsys::prefix ( char *  path  )  [static]

Set directory prefix (chdir).

Parameters:
path to change to.
Returns:
error number or 0 on success.

ssize_t ucommon::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 void ucommon::fsys::release ( fd_t  descriptor  )  [static]

Release a file descriptor.

Parameters:
descriptor to release.

fd_t ucommon::fsys::release ( void   ) 

Release descriptor, do not close.

Returns:
handle being released.

static int ucommon::fsys::rename ( char *  oldpath,
char *  newpath 
) [static]

Rename a file.

Parameters:
oldpath to rename from.
newpath to rename to.
Returns:
error number or 0 on success.

int ucommon::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.

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

Set with external descriptor.

Closes existing file if open.

Parameters:
descriptor of 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:
offset to truncate to.
Returns:
true if truncate successful.

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:
path to remove.
Returns:
error number or 0 on success.

ssize_t ucommon::fsys::write ( 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.


The documentation for this class was generated from the following file:
Generated on 14 Aug 2013 for UCommon by  doxygen 1.4.7