FILEfopen, FILEpath_fopen, FILEexists and FILEfind
Synopsis
#include avs/f_utils.h
FILEfopen(const char *filename, char *type)
FILE *
FILEpath_fopen(const char *filename, char *type, char *path, char sep)
char *
FILEfind(char *filename, char *path, char sep, int mode,
unsigned long *mod_time, int *path_index)
FILEexists (const char *filename, int mode, unsigned long *mod_time)
Description
These routines provide file handling capabilities.
FILEfopen calls the standard fopen C library routine but will perform the following preprocessing on the filename argument:
On unix machines, replaces \ characters with / characters.
On MSDOS machines replaces / characters with \ characters.
on both platforms, maps variable names specified with a prepended $ character. The definition of these variables are taken from standard system variables such as $XP_PATH<0>, $XP_PATH<1>, $MACHINE and any environment variables that you may have in your environment.
The return value contains the value returned by the fopen C library routine.
FILEpath_fopen opens the first file named filename found in a given list of directories specified by the path argument.Variables and directory separators in both the path and filename arguments are mapped as described for FILEfopen above.
FILEfind returns the absolute pathname of the file specified by filename in the specified path . The mode argument specifies permissions that this file must contain. The mod_time and path_index arguments optionally return the file modification time and an integer index specifying which directory was used to find the filename returned respectively.The return value is allocated with the malloc facility. You must call free when you are finished with this filename.
FILEexists checks whether the file exists and has the necessary permissions for the operation specified by mode. Returns 1 for success and 0 for failure. Variables and directory seperators in the filename argument are mapped as described for FILEfopen above.
Arguments
filename
A pointer to a character string that contains the name of a file.
type
A character string. The initial portion of type must consist of one of the following character sequences ( b character suffixes indicate binary file operation)
r or rb -- open for reading
w or wb -- truncate or create for writing
a or ab -- append: open for writing at end of file or create for writing
r+ , r+b, or rb+ -- open for update (reading and writing)
w+ , w+b, or wb+ -- truncate or create for update
a+ , a+b, or ab+ -- append; open for update at end-of-file or create for update
The b character indicates that the file to operate upon is binary
path
A pointer to a character string that contains a path specification. Directories in path are separated by the separator character sep .
sep
A string containing the separator character (typically either ` ` or `:').
mode
Integer specifying permissions that a file returned by FILEfind must contain. It should contain an or'd list of the flags:
FILE_EXEC (execute permission)
FILE_DIR (must be a directory)
FILE_READ (must be readable)
FILE_WRITE (must be writable)
mod_time
Returns the modification time of the file found by FILEfind as returned by the stat system call. This argument can be specified as NULL if the return of this information is not desired.
path_index
Returns an integer index specifying which directory was used to find the filename returned by FILEfind. If the first directory is used, 0 is returned, if the second directotry is used, 1 is returned, and so on. If the filename argument itself was an absolute path, the path_index value of -1 is returned (that is, no directories in path were used to find the value in this case). This argument itself can be specified as NULL if you do not need this information.