|
|
The purpose of this class is to define a low level file access class that is portable between Win32 and Posix systems. In fact win32 lacks certain critical concepts related to multi-user file ownership and yet introduces some very odd concepts of cache control and configuration based on assumed application usage. These combine to make this and the other related portable file access classes a little odd, and certainly in need of further work.
File (const char *fname, int access) |
Open an existing file of the given name with the given access mode. Valid access modes include FILE_OPEN_READONLY, FILE_OPEN_WRITEONLY, FILE_OPEN_APPEND, FILE_OPEN_READWRITE, FILE_OPEN_SYNC, and FILE_OPEN_TRUNCATE. A File "exception" is thrown if the file open fails.
Parameters:
fname | name of file path to open. |
access | mode for access to the given file. |
File (const char *fname, int access, int perm) |
Create a new file and access for use by the File class. Valid modes include FILE_OPEN_WRITEONLY, FILE_OPEN_APPEND, FILE_OPEN_SYNC, and FILE_OPEN_READWRITE. The most generic permissions for your newly created file include FILE_PERM_PRIVATE, FILE_PERM_GROUP, and FILE_PERM_PUBIC. On Posix systems, the standard chmod() permission values may be directly used, as well as the stat.h defines. As with all APE classes, an exception is thrown if the create fails.
Parameters:
fname | name of file path to create and open. |
File (const File &f) |
Open a copy of an existing "File" through a duplicate object. This essentially uses the Posix dup() call to duplicate the file descriptor involved.
Parameters:
f | an existing File class to duplicate from. |
File (int fd) |
Create a File "class" to reference an existing and already open file descriptor. This is kind of like "fdopen" in purpose, and simply allows any existing file descriptor to be manipulated by the File methods.
Parameters:
fd | an existing and already open file descriptor. |
~File () |
The destructor normally closes the File descriptor and should also release any allocated resources in a derived class.
int Read (void *buf, size_t len) |
Read an arbitrary number of bytes from the File object.
Parameters:
buf | pointer to hold read data. |
len | number of bytes to read. |
Returns: number of bytes read with success, or -1 on error.
int Write (void *buf, size_t len) |
Write an arbitrary number of bytes to the File object.
Parameters:
buf | pointer to data that will be written. |
len | number of butes to write. |
Returns: number of bytes written on success, -1 on error.
int Write (char *buf) |
A quick and easy way to write a null terminated C string to a file.
Parameters:
pointer | to null terminated string to write to the file. |
Returns: number of bytes written on success, -1 on error.
pos_t Position (pos_t pos) |
Set the current file position. This is an absolute position from the start of the file.
Parameters:
pos | new file position to set file to. |
Returns: current file position after operation.
pos_t Append (void) |
Set the current file position to the end of the file.
Returns: file position (length) of the end of the file.