LAL  7.5.0.1-b72065a
Header FileIO.h

Detailed Description

Provides standard LAL support IO functions.

Synopsis

#include <lal/LALStdio.h>
#include <lal/FileIO.h>

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...
 

Function Documentation

◆ lalstdin()

LALFILE* lalstdin ( void  )

Definition at line 63 of file FileIO.c.

◆ lalstdout()

LALFILE* lalstdout ( void  )

Definition at line 69 of file FileIO.c.

◆ lalstderr()

LALFILE* lalstderr ( void  )

Definition at line 75 of file FileIO.c.

◆ XLALFileIsCompressed()

int XLALFileIsCompressed ( const char *  path)

Definition at line 285 of file FileIO.c.

◆ XLALFileOpenRead()

LALFILE* XLALFileOpenRead ( const char *  path)

Definition at line 299 of file FileIO.c.

◆ XLALFileOpenWrite()

LALFILE* XLALFileOpenWrite ( const char *  path,
int  compression 
)

Definition at line 348 of file FileIO.c.

◆ XLALFileOpenAppend()

LALFILE* XLALFileOpenAppend ( const char *  path,
int  compression 
)

Definition at line 326 of file FileIO.c.

◆ XLALFileOpen()

LALFILE* XLALFileOpen ( const char *  path,
const char *  mode 
)

Definition at line 370 of file FileIO.c.

◆ XLALFileClose()

int XLALFileClose ( LALFILE *  file)

Definition at line 389 of file FileIO.c.

◆ XLALFileRead()

size_t XLALFileRead ( void *  ptr,
size_t  size,
size_t  nobj,
LALFILE *  file 
)

Definition at line 409 of file FileIO.c.

◆ XLALFileWrite()

size_t XLALFileWrite ( const void *  ptr,
size_t  size,
size_t  nobj,
LALFILE *  file 
)

Definition at line 424 of file FileIO.c.

◆ XLALFileGetc()

int XLALFileGetc ( LALFILE *  file)

Definition at line 439 of file FileIO.c.

◆ XLALFilePutc()

int XLALFilePutc ( int  c,
LALFILE *  file 
)

Definition at line 452 of file FileIO.c.

◆ XLALFileGets()

char* XLALFileGets ( char *  s,
int  size,
LALFILE *  file 
)

Definition at line 467 of file FileIO.c.

◆ XLALFilePuts()

int XLALFilePuts ( const char *  s,
LALFILE *  file 
)

Definition at line 480 of file FileIO.c.

◆ XLALFileVPrintf()

int XLALFileVPrintf ( LALFILE *  file,
const char *  fmt,
va_list  ap 
)

Definition at line 489 of file FileIO.c.

◆ XLALFilePrintf()

int XLALFilePrintf ( LALFILE *  file,
const char *  fmt,
  ... 
)

Definition at line 515 of file FileIO.c.

◆ XLALFileFlush()

int XLALFileFlush ( LALFILE *  file)

Definition at line 528 of file FileIO.c.

◆ XLALFileSeek()

int XLALFileSeek ( LALFILE *  file,
long  offset,
int  whence 
)

Definition at line 543 of file FileIO.c.

◆ XLALFileTell()

long XLALFileTell ( LALFILE *  file)

Definition at line 562 of file FileIO.c.

◆ XLALFileRewind()

void XLALFileRewind ( LALFILE *  file)

Definition at line 577 of file FileIO.c.

◆ XLALFileSetBuffer()

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.

Definition at line 598 of file FileIO.c.

◆ XLALFileEOF()

int XLALFileEOF ( LALFILE *  file)

Definition at line 623 of file FileIO.c.

◆ XLALFileIsRegularAndGetSize()

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

Parameters
[in]pathpath to file
[out]fileLensize in bytes of file

Definition at line 646 of file FileIO.c.

◆ XLALFileIsRegular()

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

Parameters
[in]pathpath to file

Definition at line 675 of file FileIO.c.

◆ XLALFileSize()

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

Parameters
[in]pathpath to file

Definition at line 689 of file FileIO.c.

◆ XLALFileLoad()

char* XLALFileLoad ( const char *  path)

Read a complete data-file into memory as a string.

Parameters
[in]pathinput filepath

Definition at line 235 of file FileIO.c.

◆ XLALGzipTextFile()

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.

Parameters
filename[in] The input text file.

Definition at line 707 of file FileIO.c.

◆ XLALGunzipTextFile()

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.

Parameters
filename[in] The input gzipped text file.

Definition at line 790 of file FileIO.c.

Macro Definition Documentation

◆ LALSTDIN

#define LALSTDIN   (lalstdin())

Definition at line 54 of file FileIO.h.

◆ LALSTDOUT

#define LALSTDOUT   (lalstdout())

Definition at line 55 of file FileIO.h.

◆ LALSTDERR

#define LALSTDERR   (lalstderr())

Definition at line 56 of file FileIO.h.

◆ XLAL_FILE_RESOLVE_PATH

#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.

Definition at line 116 of file FileIO.h.