Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FileIO.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007 Jolien Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20#ifndef _FILEIO_H
21#define _FILEIO_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdio.h>
28#include <stdarg.h>
29#include <lal/LALStddef.h>
30#include <lal/LALStdio.h>
31
32/**
33 * \defgroup FileIO_h Header FileIO.h
34 * \ingroup lal_support
35 *
36 * \brief Provides standard LAL support IO functions.
37 *
38 * ### Synopsis ###
39 *
40 * \code
41 * #include <lal/LALStdio.h>
42 * #include <lal/FileIO.h>
43 * \endcode
44 *
45 * Only use \ref FileIO.h in test code that links to the \c lalsupport library.
46 */
47/** @{ */
48
49typedef struct tagLALFILE LALFILE;
50
51LALFILE *lalstdin(void);
52LALFILE *lalstdout(void);
53LALFILE *lalstderr(void);
54#define LALSTDIN (lalstdin())
55#define LALSTDOUT (lalstdout())
56#define LALSTDERR (lalstderr())
57
58int XLALFileIsCompressed( const char *path );
59LALFILE *XLALFileOpenRead( const char *path );
60LALFILE *XLALFileOpenWrite( const char *path, int compression );
61LALFILE *XLALFileOpenAppend( const char *path, int compression );
62LALFILE *XLALFileOpen( const char *path, const char *mode );
63int XLALFileClose( LALFILE *file );
64size_t XLALFileRead( void *ptr, size_t size, size_t nobj, LALFILE *file );
65size_t XLALFileWrite( const void *ptr, size_t size, size_t nobj, LALFILE *file );
66int XLALFileGetc( LALFILE *file );
67int XLALFilePutc( int c, LALFILE *file );
68char *XLALFileGets( char *s, int size, LALFILE *file );
69int XLALFilePuts( const char *s, LALFILE *file );
70#ifndef SWIG /* exclude from SWIG interface */
71int XLALFileVPrintf( LALFILE *file, const char *fmt, va_list ap );
72#endif /* SWIG */
73int XLALFilePrintf( LALFILE *file, const char *fmt, ... );
74int XLALFileFlush( LALFILE *file );
75int XLALFileSeek( LALFILE *file, long offset, int whence );
76long XLALFileTell( LALFILE *file );
77void XLALFileRewind( LALFILE *file );
78int XLALFileSetBuffer( LALFILE *file, char *buf, int mode, size_t size );
79int XLALFileEOF( LALFILE *file );
80
81int XLALFileIsRegularAndGetSize ( const char *path, size_t *fileLen );
82int XLALFileIsRegular ( const char *path );
83size_t XLALFileSize ( const char *path );
84
85/** \cond DONT_DOXYGEN */
86char *XLALFileResolvePathLong ( const char *fname, const char *fallbackpath );
87char *XLALFileResolvePath ( const char *fname );
88/** \endcond */ // DONT_DOXYGEN
89
90/** 'Resolve' a given filename 'fname', returning a file path where the
91 * file can successfully be opened by fopen() using mode='rb'.
92 *
93 * Return: successful file-path or NULL if failed.
94 *
95 * Resolving uses the following algorithm: if 'fname' contains a
96 * i) (relative or absolute) path: only tries to open that path directly
97 * ii) pure filename: try
98 * 1) local dir, then
99 * 2) search $LAL_DATA_PATH, then
100 * 3) search 'fallbackpath'; relative paths are considered relative to location of liblalsupport.so (if known)
101 * return first successful hit
102 *
103 * Note: it is not an error if the given 'fname' cannot be resolved,
104 * this will simply return NULL but xlalErrno will not be set in that case.
105 *
106 * Note2: successfully resolving an 'fname' doesn't guarantee that the path points
107 * to a file, as directories can also be opened in 'rb'.
108 *
109 * Note3: the returned string is allocated here and must be XLALFree'ed by the caller.
110 *
111 * Note4: this function should only be used from within LALSuite, as it relies
112 * on macros defined by the LALSuite build system. For the public API, functions
113 * should be defined for specific types of data files, which then call
114 * XLAL_FILE_RESOLVE_PATH() internally.
115 */
116#define XLAL_FILE_RESOLVE_PATH( fname ) XLALFileResolvePathLong ( fname, LAL_FALLBACK_DATA_PATH )
117
118char *XLALFileLoad ( const char *path );
119
120int XLALGzipTextFile( const char *path );
121int XLALGunzipTextFile( const char *filename );
122
123/** @} */
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* _FILEIO_H */
LALFILE * XLALFileOpenWrite(const char *path, int compression)
Definition: FileIO.c:382
int XLALFileVPrintf(LALFILE *file, const char *fmt, va_list ap)
Definition: FileIO.c:523
int XLALGunzipTextFile(const char *filename)
Use gzip to uncompress a compressed text file.
Definition: FileIO.c:824
int XLALFileClose(LALFILE *file)
Definition: FileIO.c:423
int XLALFilePutc(int c, LALFILE *file)
Definition: FileIO.c:486
LALFILE * XLALFileOpenAppend(const char *path, int compression)
Definition: FileIO.c:360
int XLALFileEOF(LALFILE *file)
Definition: FileIO.c:657
LALFILE * XLALFileOpenRead(const char *path)
Definition: FileIO.c:333
LALFILE * lalstdin(void)
Definition: FileIO.c:66
size_t XLALFileSize(const char *path)
Return the size of given file in bytes.
Definition: FileIO.c:723
LALFILE * XLALFileOpen(const char *path, const char *mode)
Definition: FileIO.c:404
int XLALFilePuts(const char *s, LALFILE *file)
Definition: FileIO.c:514
int XLALFileIsRegular(const char *path)
Check if given file is 'regular' (rather than a directory or sth else)
Definition: FileIO.c:709
size_t XLALFileRead(void *ptr, size_t size, size_t nobj, LALFILE *file)
Definition: FileIO.c:443
int XLALFileSetBuffer(LALFILE *file, char *buf, int mode, size_t size)
Set buffering for file I/O.
Definition: FileIO.c:632
int XLALFileIsRegularAndGetSize(const char *path, size_t *fileLen)
Check if path points to a 'regular file', rather than a directory or sth else.
Definition: FileIO.c:680
int XLALFileSeek(LALFILE *file, long offset, int whence)
Definition: FileIO.c:577
int XLALFileIsCompressed(const char *path)
Definition: FileIO.c:319
size_t XLALFileWrite(const void *ptr, size_t size, size_t nobj, LALFILE *file)
Definition: FileIO.c:458
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
Definition: FileIO.c:549
void XLALFileRewind(LALFILE *file)
Definition: FileIO.c:611
int XLALGzipTextFile(const char *path)
Use gzip to compress a text file This function will use the gzip compression routines in zlib to comp...
Definition: FileIO.c:741
int XLALFileGetc(LALFILE *file)
Definition: FileIO.c:473
long XLALFileTell(LALFILE *file)
Definition: FileIO.c:596
char * XLALFileGets(char *s, int size, LALFILE *file)
Definition: FileIO.c:501
LALFILE * lalstderr(void)
Definition: FileIO.c:78
char * XLALFileLoad(const char *path)
Read a complete data-file into memory as a string.
Definition: FileIO.c:269
LALFILE * lalstdout(void)
Definition: FileIO.c:72
int XLALFileFlush(LALFILE *file)
Definition: FileIO.c:562
int compression
Definition: FileIO.c:62