fops.c - file operations
Version Tag $Id: fops.c,v 1.17 2006/02/06 19:55:46 db60 Exp $
Lvb_bool file_exists(const char *const nam);
Checks whether a file may be opened for reading. This actually tests both the presence of the file and its permissions.
Pointer to first byte of a string giving the name of the file to check.
Returns LVB_TRUE if the file exists and may be opened for reading, LVB_FALSE otherwise.
FILE *clnopen(const char *const nam, const char *const mod);
Open a file, or crash verbosely on failure.
Pointer to first byte of a string giving the name of the file to open.
Mode to open the file with. Values are as for the standard C library
function fopen
.
Returns a pointer to the newly opened file structure.
void clnclose(FILE *const fp, const char *const fnam);
Close a file, crashing verbosely on file error or failure. Or, if passed a NULL file pointer, do nothing.
Pointer to first byte of a string giving the name of the file to close.
Pointer to the file to check for errors and close, or NULL.
Returns a pointer to the newly opened file structure.
void clnremove(const char *const fnam);
Delete a file, logging a strong warning on failure.
Pointer to first byte of a string giving the name of the file to delete.
None.
For portability, the file should not be open on calling clnremove
.
char *f2str(FILE *const stream);
Read contents of a file into a new string. The text read is terminated by
newline if not already present, and finally by '\0'. The file is treated
as text. One may deallocate memory for the new string using the standard
library function free
.
Pointer to file, which must be open in a readable mode and positioned at the start.
Pointer to first byte in string containing the contents of the file when read as text.
Does not know how to interpret newlines if the file has a different representation of newline to that used by the current system.
Will not work correctly if the file size alters during the call to f2str
.
Does not work correctly if the stream is positioned anywhere other than
at the start of the file on calling f2str
.