Provides standard LAL support IO functions.
Only use FileIO.h in test code that links to the lalsupport
library.
Prototypes | |
LALFILE * | lalstdin (void) |
LALFILE * | lalstdout (void) |
LALFILE * | lalstderr (void) |
int | XLALFileIsCompressed (const char *path) |
LALFILE * | XLALFileOpenRead (const char *path) |
LALFILE * | XLALFileOpenWrite (const char *path, int compression) |
LALFILE * | XLALFileOpenAppend (const char *path, int compression) |
LALFILE * | XLALFileOpen (const char *path, const char *mode) |
int | XLALFileClose (LALFILE *file) |
size_t | XLALFileRead (void *ptr, size_t size, size_t nobj, LALFILE *file) |
size_t | XLALFileWrite (const void *ptr, size_t size, size_t nobj, LALFILE *file) |
int | XLALFileGetc (LALFILE *file) |
int | XLALFilePutc (int c, LALFILE *file) |
char * | XLALFileGets (char *s, int size, LALFILE *file) |
int | XLALFilePuts (const char *s, LALFILE *file) |
int | XLALFileVPrintf (LALFILE *file, const char *fmt, va_list ap) |
int | XLALFilePrintf (LALFILE *file, const char *fmt,...) |
int | XLALFileFlush (LALFILE *file) |
int | XLALFileSeek (LALFILE *file, long offset, int whence) |
long | XLALFileTell (LALFILE *file) |
void | XLALFileRewind (LALFILE *file) |
int | XLALFileSetBuffer (LALFILE *file, char *buf, int mode, size_t size) |
Set buffering for file I/O. More... | |
int | XLALFileEOF (LALFILE *file) |
int | XLALFileIsRegularAndGetSize (const char *path, size_t *fileLen) |
Check if path points to a 'regular file', rather than a directory or sth else. More... | |
int | XLALFileIsRegular (const char *path) |
Check if given file is 'regular' (rather than a directory or sth else) More... | |
size_t | XLALFileSize (const char *path) |
Return the size of given file in bytes. More... | |
char * | XLALFileLoad (const char *path) |
Read a complete data-file into memory as a string. More... | |
int | XLALGzipTextFile (const char *path) |
Use gzip to compress a text file This function will use the gzip compression routines in zlib to compress a text file. More... | |
int | XLALGunzipTextFile (const char *filename) |
Use gzip to uncompress a compressed text file. More... | |
Macros | |
#define | LALSTDIN (lalstdin()) |
#define | LALSTDOUT (lalstdout()) |
#define | LALSTDERR (lalstderr()) |
#define | XLAL_FILE_RESOLVE_PATH(fname) XLALFileResolvePathLong ( fname, LAL_FALLBACK_DATA_PATH ) |
'Resolve' a given filename 'fname', returning a file path where the file can successfully be opened by fopen() using mode='rb'. More... | |
LALFILE* XLALFileOpenWrite | ( | const char * | path, |
int | compression | ||
) |
LALFILE* XLALFileOpenAppend | ( | const char * | path, |
int | compression | ||
) |
LALFILE* XLALFileOpen | ( | const char * | path, |
const char * | mode | ||
) |
size_t XLALFileRead | ( | void * | ptr, |
size_t | size, | ||
size_t | nobj, | ||
LALFILE * | file | ||
) |
size_t XLALFileWrite | ( | const void * | ptr, |
size_t | size, | ||
size_t | nobj, | ||
LALFILE * | file | ||
) |
int XLALFileVPrintf | ( | LALFILE * | file, |
const char * | fmt, | ||
va_list | ap | ||
) |
int XLALFilePrintf | ( | LALFILE * | file, |
const char * | fmt, | ||
... | |||
) |
int XLALFileSeek | ( | LALFILE * | file, |
long | offset, | ||
int | whence | ||
) |
int XLALFileSetBuffer | ( | LALFILE * | file, |
char * | buf, | ||
int | mode, | ||
size_t | size | ||
) |
Set buffering for file I/O.
For a regular file buffering will be set using setvbuf
. If buf
is NULL
then a buffer of size
will be automatically allocated. The mode
can be _IONBF
, _IOLBF
or _IOFBF
for no buffering, line buffering or full buffering respectively.
For a compressed file the buffering will be set with gzbuffer
. The buf
and mode
inputs are ignored and a buffer of size
is set.
int XLALFileIsRegularAndGetSize | ( | const char * | path, |
size_t * | fileLen | ||
) |
Check if path points to a 'regular file', rather than a directory or sth else.
and also return the size of the given file.
This is simply a wrapper to stat(), and S_ISREG() and could be easily generalized along those lines to test for directories etc.
return an error if stat() was unavailable return 1 for true, 0 for false, -1 on error
[in] | path | path to file |
[out] | fileLen | size in bytes of file |
int XLALFileIsRegular | ( | const char * | path | ) |
Check if given file is 'regular' (rather than a directory or sth else)
This is a simple wrapper to XLALFileIsRegularAndGetSize().
Return 1 for true, 0 for false, -1 on error
[in] | path | path to file |
size_t XLALFileSize | ( | const char * | path | ) |
Return the size of given file in bytes.
This is simply a wrapper to XLALFileIsRegularAndGetSize()
Returns (size_t)-1 on error
[in] | path | path to file |
char* XLALFileLoad | ( | const char * | path | ) |
int XLALGzipTextFile | ( | const char * | filename | ) |
Use gzip to compress a text file This function will use the gzip compression routines in zlib
to compress a text file.
The compressed file will have the extension ".gz" and the original uncompressed file will be removed.
filename | [in] The input text file. |
int XLALGunzipTextFile | ( | const char * | filename | ) |
Use gzip to uncompress a compressed text file.
This function will use the gzip compression routines in zlib
to uncompress a gzipped text file. The compressed file should have the ".gz" extension otherwise it will be rejected. The output will have the same filename with the ".gz" extension removed. The compressed file will be removed.
Note: gzopen
will check the file's "magic number" to see if it is a gzipped file. If it's not a gzipped file it will still open the file for reading as a standard file.
filename | [in] The input gzipped text file. |
#define XLAL_FILE_RESOLVE_PATH | ( | fname | ) | XLALFileResolvePathLong ( fname, LAL_FALLBACK_DATA_PATH ) |
'Resolve' a given filename 'fname', returning a file path where the file can successfully be opened by fopen() using mode='rb'.
Return: successful file-path or NULL if failed.
Resolving uses the following algorithm: if 'fname' contains a i) (relative or absolute) path: only tries to open that path directly ii) pure filename: try 1) local dir, then 2) search $LAL_DATA_PATH, then 3) search 'fallbackpath'; relative paths are considered relative to location of liblalsupport.so (if known) return first successful hit
Note: it is not an error if the given 'fname' cannot be resolved, this will simply return NULL but xlalErrno will not be set in that case.
Note2: successfully resolving an 'fname' doesn't guarantee that the path points to a file, as directories can also be opened in 'rb'.
Note3: the returned string is allocated here and must be XLALFree'ed by the caller.
Note4: this function should only be used from within LALSuite, as it relies on macros defined by the LALSuite build system. For the public API, functions should be defined for specific types of data files, which then call XLAL_FILE_RESOLVE_PATH() internally.