UCommon
Public Member Functions | Static Public Member Functions
ucommon::dir Class Reference

Convenience class for directories. More...

#include <fsys.h>

Inheritance diagram for ucommon::dir:
Inheritance graph
[legend]
Collaboration diagram for ucommon::dir:
Collaboration graph
[legend]

Public Member Functions

void close (void)
 Close and release directory object.
 
 dir (const char *path)
 Construct and open a directory path. More...
 
 dir ()
 Construct an unopened directory.
 
int err (void) const
 
void open (const char *path)
 Open a directory path for reading. More...
 
 operator bool () const
 Test if file descriptor is open. More...
 
bool operator! () const
 Test if file descriptor is closed. More...
 
ssize_t read (char *buffer, size_t count)
 Read data from directory. More...
 
void reset (void)
 
 ~dir ()
 Close and release directory.
 

Static Public Member Functions

static int create (const char *path, unsigned mode)
 Simple direct method to create a directory. More...
 
static int remove (const char *path)
 Remove an empty directory. More...
 

Additional Inherited Members

- Private Types inherited from ucommon::fsys
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.
 
typedef struct stat fileinfo_t
 
typedef long offset_t
 File offset type.
 
- Private Member Functions inherited from ucommon::fsys
void assign (fd_t descriptor)
 Assign descriptor directly. More...
 
int close (void)
 Close a fsys resource. More...
 
int drop (offset_t size=0)
 Drop cached data from start of file. More...
 
int err (void) const
 Get last error. More...
 
 fsys ()
 Construct an unattached fsys descriptor.
 
 fsys (fd_t handle)
 Contruct fsys from raw file handle.
 
 fsys (const fsys &descriptor)
 Copy (dup) an existing fsys descriptor. More...
 
 fsys (const char *path, access_t access)
 Create a fsys descriptor by opening an existing file or directory. More...
 
 fsys (const char *path, unsigned permission, access_t access)
 Create a fsys descriptor by creating a file. More...
 
fd_t handle (void) const
 Get the native system descriptor handle of the file descriptor. More...
 
int info (fileinfo_t *buffer)
 Get status of open descriptor. More...
 
bool is_tty (void)
 See if current file stream is a tty device. More...
 
void open (const char *path, access_t access)
 Open a file or directory. More...
 
void open (const char *path, unsigned mode, access_t access)
 Open a file descriptor directly. More...
 
 operator bool () const
 Test if file descriptor is open. More...
 
 operator fd_t () const
 Get the descriptor from the object by casting reference. More...
 
bool operator! () const
 Test if file descriptor is closed. More...
 
fd_t operator* () const
 Get the descriptor from the object by pointer reference. More...
 
void operator*= (fd_t &descriptor)
 Replace current file descriptor with an external descriptor. More...
 
void operator= (const fsys &descriptor)
 Assign file descriptor by duplicating another descriptor. More...
 
void operator= (fd_t descriptor)
 Assing file descriptor from system descriptor. More...
 
ssize_t read (void *buffer, size_t count)
 Read data from descriptor or scan directory. More...
 
fd_t release (void)
 Release descriptor, do not close. More...
 
void reset (void)
 Reset error flag.
 
int seek (offset_t offset)
 Set the position of a file descriptor. More...
 
void set (fd_t descriptor)
 Set with external descriptor. More...
 
int sync (void)
 Commit changes to the filesystem. More...
 
int trunc (offset_t offset)
 Truncate file to specified length. More...
 
ssize_t write (const void *buffer, size_t count)
 Write data to descriptor. More...
 
 ~fsys ()
 Close and release a file descriptor.
 
- Static Private Member Functions inherited from ucommon::fsys
static fd_t append (const char *path)
 Direct means to create or append a writable path and return descriptor. More...
 
static void assign (fsys &object, fd_t descriptor)
 Assign a descriptor directly. More...
 
static int copy (const char *source, const char *target, size_t size=1024)
 Copy a file. More...
 
static int erase (const char *path)
 Erase (remove) a file only. More...
 
static int exec (const char *path, char **argv, char **envp=((void *) 0))
 Execute a process and get exit code. More...
 
static int hardlink (const char *path, const char *target)
 Create a hard link. More...
 
static int info (const char *path, fileinfo_t *buffer)
 Stat a file. More...
 
static int inherit (fd_t &descriptor, bool enable)
 Changle inheritable handle. More...
 
static fd_t input (const char *path)
 Direct means to open a read-only file path and return a descriptor. More...
 
static bool is_char (struct stat *inode)
 
static bool is_dev (struct stat *inode)
 
static bool is_device (const char *path)
 Test if path is a device path. More...
 
static bool is_dir (const char *path)
 Test if path is a directory. More...
 
static bool is_dir (struct stat *inode)
 
static bool is_disk (struct stat *inode)
 
static bool is_executable (const char *path)
 Test if path is executable. More...
 
static bool is_exists (const char *path)
 Test if path exists. More...
 
static bool is_file (const char *path)
 Test if path is a file. More...
 
static bool is_file (struct stat *inode)
 
static bool is_hidden (const char *path)
 Test if path is a hidden file. More...
 
static bool is_link (const char *path)
 Test if path is a symlink. More...
 
static bool is_link (struct stat *inode)
 
static bool is_readable (const char *path)
 Test if path readable. More...
 
static bool is_sys (struct stat *inode)
 
static bool is_tty (fd_t fd)
 See if the file handle is a tty device. More...
 
static bool is_writable (const char *path)
 Test if path writable. More...
 
static int link (const char *path, const char *target)
 Create a symbolic link. More...
 
static int linkinfo (const char *path, char *buffer, size_t size)
 Read a symbolic link to get it's target. More...
 
static int load (const char *path)
 Load a library into memory. More...
 
static int mode (const char *path, unsigned value)
 Change file access mode. More...
 
static fd_t null (void)
 Create inheritable /dev/null handle. More...
 
static fd_t output (const char *path)
 Direct means to create or access a writable path and return descriptor. More...
 
static int pipe (fd_t &input, fd_t &output, size_t size=0)
 Create pipe. More...
 
static int prefix (const char *path)
 Set directory prefix (chdir). More...
 
static int prefix (char *path, size_t size)
 Get current directory prefix (pwd). More...
 
static string_t prefix (void)
 
static void release (fd_t descriptor)
 Release a file descriptor. More...
 
static int remapError (void)
 
static int rename (const char *oldpath, const char *newpath)
 Rename a file. More...
 
static int unlink (const char *path)
 Remove a symbolic link explicitly. More...
 
- Static Private Attributes inherited from ucommon::fsys
static const offset_t end
 Used to mark "append" in set position operations.
 

Detailed Description

Convenience class for directories.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 716 of file fsys.h.

Constructor & Destructor Documentation

ucommon::dir::dir ( const char *  path)

Construct and open a directory path.

Parameters
pathof directory.

Member Function Documentation

static int ucommon::dir::create ( const 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.
void ucommon::dir::open ( const char *  path)

Open a directory path for reading.

Parameters
pathto open.
ucommon::dir::operator bool ( ) const
inline

Test if file descriptor is open.

Returns
true if open.

Definition at line 787 of file fsys.h.

bool ucommon::dir::operator! ( ) const
inline

Test if file descriptor is closed.

Returns
true if closed.

Definition at line 794 of file fsys.h.

ssize_t ucommon::dir::read ( char *  buffer,
size_t  count 
)

Read data from directory.

Parameters
bufferto read into.
countof bytes to read.
Returns
bytes transferred, -1 if error.
static int ucommon::dir::remove ( const char *  path)
static

Remove an empty directory.

Parameters
pathof directory.
Returns
error number or 0 on success.

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