
Home |
|
PegFile
|

Examples |

Index |
|
 |
 |
|
PegImageConvert
Constructors:
 |
 |
PegFile(void)
|
 |
PegFile(const char *filename, const char *mode)
|
 |
PegFile(KP_TFILE *fd)
|
The first constructor creates a PegFile object
with no active file.
The second constructor creates a PegFile object
and uses it to open the file referenced by filename
in the file mode specified by parameter mode.
The use of this constructor is equivalent to using the first
constructor to create the PegFile object, followed
immediately by a call to the object's Open() member
function to open the file.
The third constructor creates a PegFile object
and attaches to it the open file specified by fd.
Parameter fd is a file descriptor, a handle to a file
already opened by your application with a direct call to the underlying
file system services.
The use of this constructor is equivalent to using the first
constructor to create the PegFile object, followed
immediately by a call to the object's Attach() member
function to attach the open file.
Public Functions:
 |
 |
int Attach(KP_TFILE *fd)
|
This function attaches the open file specified by fd
to the PegFile object and returns the value 0.
Parameter fd is the file descriptor of a file
already opened by your application with a direct call to the underlying
file system services.
The function returns EOF if the PegFile object
currently has a file open.
 |
 |
int Close(void)
|
This function closes the PegFile object's currently
open file and returns the value 0.
The function returns EOF if the file cannot be closed or if
the PegFile object currently has no open file.
 |
 |
KP_TFILE *Detach(void)
|
This function detaches the currently open file from the
PegFile object and returns the file descriptor (handle)
to the caller.
The file descriptor is the value used by the underlying
file system to identify the file. The file remains open.
The function returns NULL if the PegFile object
currently has no open file.
 |
 |
int IsOpen(void)
|
This function returns a non-zero value if the PegFile object
has a file open. Otherwise, the function returns the value 0.
 |
 |
int Open(const char *filename,
|
| |

const char *mode)
|
This function opens the file referenced by filename
in the file mode specified by parameter mode.
The allowable file name format and file access modes are those
specified by standard C and supported by your file system.
The opened file is attached to the PegFile object.
The function returns 0 if the file is successfully opened.
The function returns EOF if the file cannot be opened or if
the PegFile object currently has a file open.
 |
 |
int OpenTemp(void)
|
This function creates and opens a temporary file.
The file is opened for read and write binary access.
The function returns 0 if the file is successfully
created and opened.
The function returns EOF if the file cannot be created or
opened or if the PegFile object currently has a file open.
The temporary file will be automatically removed (deleted)
when the file is closed by member function Close().
 |
 |
size_t Read(void *buf,
|
| |

size_t size, size_t cnt)
|
This function reads cnt elements of size bytes each
from the file into the memory buffer referenced by pointer buf.
The function returns n, the number of complete elements
of the requested size successfully read. If n is less than
cnt, the file may be at end of file or an error may have occurred,
in which case the state of the file pointer is indeterminate.
The function returns 0 if cnt or size
is 0 or if no complete elements can be read.
 |
 |
static int Remove(const char *filename)
|
This function removes (deletes) the file referenced by filename.
The allowable file name format is that supported by your file system.
The function returns the value 0 if the file is
successfully deleted. Otherwise, the function returns EOF.
 |
 |
int Seek(long offset, int origin)
|
This function sets the file pointer to the file location that is
offset bytes from the specified origin.
Set origin to SEEK_CUR to seek from the
current file location, SEEK_END to seek from the
end of the file or SEEK_SET to seek from the
beginning of the file.
The function returns 0 if the file pointer is successfully
moved. Otherwise a non-zero value is returned.
 |
 |
long Tell(void)
|
This function returns the current file pointer value measured as the
number of bytes from the beginning of the file.
The value -1 is returned if the file pointer location
is indeterminate.
 |
 |
size_t Write(const void *buf,
|
| |

size_t size, size_t cnt)
|
This function writes cnt elements of size bytes each
to the file from the memory buffer referenced by pointer buf.
The function returns n, the number of complete elements
of the requested size successfully written. Value n will be
less than cnt if an error occurs.
The function returns 0 if cnt or size
is 0 or if no complete elements can be written.
The example provided with the
PegQuant class
creates a PegFile object
which is used to read several graphic files to create an
optimal palette for displaying the images from the files.