#include <file.h>
Inheritance diagram for Dv::Util::File:
Public Types | |
enum | Type { REGULAR, SYMLINK, DIRECTORY, SPECIALCHAR, SPECIALBLOCK, FIFO, SOCKET, OTHER, NONEXISTENT } |
Type of file, note NONEXISTENT for pathnames that do not refer to a file. More... | |
enum | Mode { READ_OWNER = 0400, WRITE_OWNER = 0200, EXEC_OWNER = 0100, READ_GROUP = 040, WRITE_GROUP = 020, EXEC_GROUP = 010, READ_OTHER = 04, WRITE_OTHER = 02, EXEC_OTHER = 01, SETUID = 04000, SETGID = 02000, RWX_OWNER = 0700, RWX_GROUP = 070, RWX_OTHER = 07, RW_OWNER = 0600, RW_GROUP = 060, RW_OTHER = 06 } |
File permissions, you can use the | operator to combine them. More... | |
Public Member Functions | |
File (const std::string &path) throw (FileError) | |
Constructor, argument can be a relative or an absolute path. | |
File (const File &f) throw (FileError) | |
Copy constructor. | |
File & | operator= (const File &f) throw (FileError) |
Assignment. | |
virtual | ~File () |
Virtual destructor, calls unmap(). | |
File & | expand () throw (FileError) |
Change File object to a non-symbolic link file by expanding symbolic links, if any. | |
bool | exists () const throw (FileError) |
Check existence of file. | |
operator bool () const throw (FileError) | |
Delegates to exists(). | |
std::string | str () const |
Returns a full, clean, absolute path as given by ::realpath(3C). | |
operator const char * () const | |
Delegates to str(). | |
const char * | path () const |
Identical to str().c_str(). | |
std::string | fullpath () const throw (FileError) |
Retrieve full path without resolving symbolic links. | |
std::string | realpath () const throw (FileError) |
Only useful for symbolic links. | |
std::string | relpath (const std::string &from) const throw (FileError) |
Return path relative to from, which must be absolute. | |
std::string | relpath () const throw (FileError) |
Return path relative to Directory::pwd(). | |
Type | type () const throw (FileError) |
Return type of file (possibly File::NONEXISTENT). | |
bool | isdir () const throw (FileError) |
Return true iff type() == File::DIRECTORY. | |
size_t | size () const throw (FileError) |
Return size in bytes of file, 0 if !exists(). | |
time_t | last_modified () const throw (FileError) |
Return time of last modification of file, or 0 if it does not exist. | |
time_t | last_accessed () const throw (FileError) |
Return time of last access to file, or 0 if it does not exist. | |
mode_t | mode () const throw (FileError) |
Return permissions of file,. | |
uid_t | owner () const throw (FileError) |
Return uid of owner of file. | |
gid_t | group () const throw (FileError) |
Return gid of group-owner of file. | |
bool | chown (uid_t uid) const throw (FileError) |
Change the ownership of an existing file, return true iff successful. | |
bool | chgrp (const char *groupname) const throw (FileError) |
Change group-ownership of an existing file, return true iff successful. | |
bool | chmod (int mode=0755) throw (FileError) |
Change permissions on an existing file. | |
bool | rm () throw (FileError) |
Remove a file, for directories, rmdir is used. | |
void | rmfr () throw (FileError) |
Like rm -fr. | |
bool | mv (const std::string &newpath) throw (FileError) |
Rename file, return true iff succeeds, also renames *this. | |
bool | touch (int mode=0644) throw (FileError) |
Creates or updates modification time of file. | |
bool | mkdir (int mode=0755) throw (FileError) |
Create a directory str(), precondition is !exists(). | |
bool | mklink (const std::string &path) throw (FileError) |
Create a hard link to path, precondition is !exists(). | |
bool | mksymlink (const std::string &path) throw (FileError) |
Create a symbolic link to path. | |
const void * | map () throw (FileError) |
Map the contents of an existing file into memory. | |
void | unmap () throw (FileError) |
Release a mapping, if any, obtained by File::map(). | |
const void * | mapped () const |
std::string & | content (std::string &s) const throw (FileError) |
Append contents of file to string. | |
std::string | content () const throw (FileError) |
Return contents of file to string. | |
Static Public Member Functions | |
const std::string & | typestr (Type) throw (FileError) |
Return string representation of File::Type. | |
std::string | absolute_path (const std::string &path) throw (FileError) |
Returns a full, clean, absolute path as given by ::realpath(3C). | |
std::string & | fullpath (std::string path, std::string &resolved_path) throw (FileError) |
Retrieve full path without resolving symbolic links. | |
Protected Member Functions | |
virtual void | refresh () const throw (FileError) |
Updates private data members, exist_ and type_. | |
Protected Attributes | |
bool | exist_ |
True iff there is a file with pathname str(). | |
Type | type_ |
Type of file. | |
Private Attributes | |
stat | stats_ |
std::string | path_ |
void * | addr_ |
Friends | |
bool | operator== (const File &, const File &) |
Compare File objects. | |
bool | operator!= (const File &f1, const File &f2) |
Compare File objects. | |
bool | operator< (const File &, const File &) |
Compare File objects. |
Example usage:
const char* name; File f(name); if (f.exists()) { Date d(f.last_modified()); cout << f.str() << endl; cout << std::string(d) << endl; const char* pc = static_cast<const char*>(f.map()); if (pc) // note: pc is not necessarily a C string for (unsigned int i=0;(i<f.size());++i,++pc) cout << *pc; } else f.touch(); // make it exist
Definition at line 67 of file file.h.
|
Type of file, note NONEXISTENT for pathnames that do not refer to a file.
|
|
File permissions, you can use the | operator to combine them.
|
|
Constructor, argument can be a relative or an absolute path.
|
|
Copy constructor.
|
|
Virtual destructor, calls unmap().
|
|
Assignment.
|
|
Change File object to a non-symbolic link file by expanding symbolic links, if any.
|
|
Return string representation of File::Type.
|
|
Check existence of file. Definition at line 133 of file file.h. References exist_, and refresh(). Referenced by operator bool(). |
|
Delegates to exists(). Definition at line 135 of file file.h. References exists(). |
|
Returns a full, clean, absolute path as given by ::realpath(3C).
References path_. |
|
Returns a full, clean, absolute path as given by ::realpath(3C).
|
|
Delegates to str(). Definition at line 147 of file file.h. References path_. |
|
Identical to str().c_str().
References path_. |
|
Retrieve full path without resolving symbolic links. The result is absolute and does not contain '..' or '.' components and no superfluous '/' chars.
|
|
Retrieve full path without resolving symbolic links. The result is absolute and does not contain '..' or '.' components and no superfluous '/' chars.
|
|
Only useful for symbolic links.
|
|
Return path relative to from, which must be absolute.
|
|
Return path relative to Directory::pwd().
|
|
Return type of file (possibly File::NONEXISTENT).
Referenced by isdir(). |
|
Return true iff type() == File::DIRECTORY. |
|
Return size in bytes of file, 0 if !exists().
|
|
Return time of last modification of file, or 0 if it does not exist.
|
|
Return time of last access to file, or 0 if it does not exist.
|
|
Return permissions of file,.
|
|
Return uid of owner of file.
|
|
Return gid of group-owner of file.
|
|
Change the ownership of an existing file, return true iff successful.
|
|
Change group-ownership of an existing file, return true iff successful.
|
|
Change permissions on an existing file.
|
|
Remove a file, for directories, rmdir is used.
|
|
Like rm -fr. |
|
Rename file, return true iff succeeds, also renames *this.
|
|
Creates or updates modification time of file.
|
|
Create a directory str(), precondition is !exists().
|
|
Create a hard link to path, precondition is !exists().
|
|
Create a symbolic link to path.
|
|
Map the contents of an existing file into memory. Return 0 upon failure. Map() returns a pointer to the contents of the file, mapped into virtual memory
|
|
Release a mapping, if any, obtained by File::map(). Unmapping a file that is not mapped is a noop. File::unmap() is automatically called by the destructor.
|
|
References addr_. |
|
Append contents of file to string.
|
|
Return contents of file to string.
|
|
Updates private data members, exist_ and type_.
Reimplemented in Dv::Util::Directory.
Referenced by exists(), and Dv::Util::Directory::files(). |
|
Compare File objects. File comparison is independent of the name, the operator compares i-nodes and devices. Nonexistent File objects are never equal.
|
|
Compare File objects. File comparison is independent of the name, the operator compares i-nodes and devices. Nonexistent File objects are never equal.
|
|
Compare File objects. File comparison is independent of the name, the operator compares i-nodes and devices. Nonexistent File objects are never equal.
|
|
True iff there is a file with pathname str(). Definition at line 334 of file file.h. Referenced by exists(). |
|
Type of file. |
|
|
Definition at line 339 of file file.h. Referenced by operator const char *(), path(), and str(). |
|
Definition at line 340 of file file.h. Referenced by mapped(). |
dvutil-0.13.15 | [30 December, 2004] |