Table of Contents

NAME

QccFileExists, QccFileOpen, QccFileDescriptorOpen, QccFileClose, QccFileRemove, QccFileGetSize, QccFileGetModTime, QccFileGetRealPath, QccFileGetCurrentPosition, QccFileRewind - file-access routines

SYNOPSIS

#include "libQccPack.h"

int QccFileExists(const QccString filename);
int QccFileGetExtension(const QccString filename, QccString extension);
FILE *QccFileOpen(const QccString filename, QccString mode);
FILE *QccFileDescriptorOpen(int file_descriptor, const QccString mode);
int QccFileClose(FILE *fileptr);
int QccFileSeekable(FILE *fileptr);
int QccFileFlush(FILE *fileptr);
int QccFileRemove(const QccString filename);
int QccFileGetSize(const QccString filename, FILE *fileptr, long *filesize);
int QccFileGetModTime(const QccString filename, FILE *fileptr, long *time);
int QccFileGetRealPath(const QccString filename, QccString path);
int QccFileGetCurrentPosition(FILE *infile, long *current_position);
int QccFileRewind(FILE *infile);

DESCRIPTION

QccFileExists() returns 1 if the file specified by filename exists, or 0 otherwise.

QccFileGetExtension() examines filename and returns in extension the filename extension, the substring of filename appearing after the final '.'. If filename has no '.' in it, then QccFileGetExtension() returns with a raturn value of 1 and a zero-length string in extension. If the substring following the final '.' is "gz" (i.e., it is a gzip(1) -compressed file), then the substring between the next-to-last '.' and the last '.' is returned as extension.

QccFileOpen() opens the file specified by filename for reading (mode = "r") or writing (mode = "w"). If filename indicates that the file is compressed, QccFileOpen() opens the file for reading or writing compressed data (see "COMPRESSED-FILE ACCESS" below). Upon succesful completion, QccFileOpen() returns a FILE pointer. Otherwise, NULL is returned.

QccFileDescriptorOpen() returns a FILE pointer for the file descriptor file_descriptor. Usually, file_descriptor is produced by opening a file via open(2) or a pipe via pipe(2) . QccFileDescriptorOpen() calls fdopen(3) .

QccFileClose() closes a file previously opened by QccFileOpen() or QccFileDescriptorOpen(). If fileptr does not correspond to a file opened by QccFileOpen() or QccFileDescriptorOpen(), QccFileClose() returns 1; otherwise a successful completion is indicated by a return value of 0.

QccFileSeekable() returns 1 if fileptr is a seekable stream (i.e., not a pipe, socket, or FIFO), or 0 otherwise.

QccFileFlush() flushes the fileptr stream. See fflush(3) .

QccFileRemove() removes (deletes) the file named by filename. If the remove fails for whatever reason (nonexistent file, insufficient privilege for the remove, etc.) a value of 1 is returned; 0 is returned on success.

QccFileGetSize() returns the size of the file in bytes in the location pointed to by filesize. The file can be specified by either its filename, or by giving a FILE pointer to it. The size of a compressed file cannot be determined from a FILE pointer, so use the filename method.

QccFileGetModTime() returns the modtime (time of last modification) of the file in the location pointed to by modtime. The file can be specified by either its filename, or by giving a FILE pointer to it. The modtime of a compressed file cannot be determined from a FILE pointer, so use the filename method. QccFileGetModTime() returns 0 for successful completion, 1 otherwise.

QccFileGetRealPath() expands all symbolic links, resolves references to '.' and '..', and removes extra '/' characters in filename to produce a canonicalized absolute pathname to the file which is retured in path. Internally, realpath(3) is used.

QccFileGetCurrentPosition() returns the current value of the file-position indicator for the stream pointed to by infile; the current position is returned in the location pointed to by current_position. QccFileGetCurrentPosition() does not work for compressed files. QccFileGetCurrentPosition() returns 0 for successful completion, 1 otherwise.

QccFileRewind() moves the file-position indicator for the stream pointed to by infile to the start of the file. QccFileRewind() does not work for compressed files. QccFileRewind() returns 0 for successful completion, 1 otherwise.

COMPRESSED-FILE ACCESS

The QccPack file-access routines are able to read and write compressed files created by gzip(1) . When opening a file for reading or writing, QccFileOpen() checks the filename for a ".Z" or ".gz" extension. If the filename has one of these extensions, it is assumed that the file is compressed. In this case, QccFileOpen() opens a pipe (via popen(3) ) to gzip(1) (for writing) or gunzip(1) (for reading). All reading and writing of data to the compressed file then goes through the pipe.

For each FILE pointer returned by QccFileOpen(), the QccPack library keeps track of whether the pointer corresponds to an actual file or a pipe; QccFileClose() then closes the file appropriately by calling fclose(3) or pclose(3) as needed.

SEE ALSO

fopen(3) , popen(3) , open(2) , fdopen(3) , pipe(2) , realpath(3) , gzip(1) , gunzip(1) , QccPack(3)

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads