file IO related operations. More...
#include <stdio.h>
#include <sys/stat.h>
#include <sphinxbase_export.h>
#include <prim_type.h>
Go to the source code of this file.
Data Structures | |
struct | lineiter_t |
Line iterator for files. More... | |
Defines | |
#define | myfopen(file, mode) _myfopen((file),(mode),__FILE__,__LINE__) |
Typedefs | |
typedef struct lineiter_t | lineiter_t |
Line iterator for files. | |
Functions | |
SPHINXBASE_EXPORT FILE * | fopen_comp (const char *file, const char *mode, int32 *ispipe) |
Like fopen, but use popen and zcat if it is determined that "file" is compressed (i.e., has a .z, .Z, .gz, or .GZ extension). | |
SPHINXBASE_EXPORT void | fclose_comp (FILE *fp, int32 ispipe) |
Close a file opened using fopen_comp. | |
SPHINXBASE_EXPORT FILE * | fopen_compchk (const char *file, int32 *ispipe) |
Open a file for reading, but if file not present try to open compressed version (if file is uncompressed, and vice versa). | |
SPHINXBASE_EXPORT FILE * | _myfopen (const char *file, const char *mode, const char *pgm, int32 line) |
Wrapper around fopen to check for failure and E_FATAL if failed. | |
SPHINXBASE_EXPORT int32 | fread_retry (void *pointer, int32 size, int32 num_items, FILE *stream) |
NFS file reads seem to fail now and then. | |
SPHINXBASE_EXPORT char * | fread_line (FILE *stream, size_t *out_len) |
Read a line of arbitrary length from a file and return it as a newly allocated string. | |
SPHINXBASE_EXPORT lineiter_t * | lineiter_start (FILE *fh) |
Start reading lines from a file. | |
SPHINXBASE_EXPORT lineiter_t * | lineiter_next (lineiter_t *li) |
Move to the next line in the file. | |
SPHINXBASE_EXPORT void | lineiter_free (lineiter_t *li) |
Stop reading lines from a file. | |
SPHINXBASE_EXPORT int32 | stat_retry (const char *file, struct stat *statbuf) |
Like fread_retry, but for stat. | |
SPHINXBASE_EXPORT int32 | stat_mtime (const char *file) |
Return time of last modification for the given file, or -1 if stat fails. |
file IO related operations.
Custom fopen with error checking is implemented. fopen_comp can open a file with .z, .Z, .gz or .GZ extension
WARNING: Usage of stat_retry will results in 100s of waiting time if the file doesn't exist.
Definition in file pio.h.
SPHINXBASE_EXPORT void fclose_comp | ( | FILE * | fp, | |
int32 | ispipe | |||
) |
Close a file opened using fopen_comp.
fp | In: File pointer to be closed | |
ispipe | In: ispipe argument that was returned by the corresponding fopen_comp() call |
Definition at line 149 of file pio.c.
References fclose_comp().
Referenced by fclose_comp().
SPHINXBASE_EXPORT FILE* fopen_comp | ( | const char * | file, | |
const char * | mode, | |||
int32 * | ispipe | |||
) |
Like fopen, but use popen and zcat if it is determined that "file" is compressed (i.e., has a .z, .Z, .gz, or .GZ extension).
file | In: File to be opened | |
mode | In: "r" or "w", as with normal fopen | |
ispipe | Out: On return *ispipe is TRUE iff file was opened via a pipe |
Definition at line 53 of file pio.c.
References E_ERROR, E_ERROR_SYSTEM, E_FATAL, and fopen_comp().
Referenced by fopen_comp(), and fopen_compchk().
SPHINXBASE_EXPORT FILE* fopen_compchk | ( | const char * | file, | |
int32 * | ispipe | |||
) |
Open a file for reading, but if file not present try to open compressed version (if file is uncompressed, and vice versa).
file | In: File to be opened | |
ispipe | Out: On return *ispipe is TRUE iff file was opened via a pipe |
Definition at line 166 of file pio.c.
References E_ERROR_SYSTEM, E_WARN, fopen_comp(), and fopen_compchk().
Referenced by fopen_compchk().
SPHINXBASE_EXPORT char* fread_line | ( | FILE * | stream, | |
size_t * | out_len | |||
) |
Read a line of arbitrary length from a file and return it as a newly allocated string.
stream | The file handle to read from. | |
out_len | Output: if not NULL, length of the string read. |
Definition at line 290 of file pio.c.
References ckd_malloc, ckd_realloc, and fread_line().
Referenced by fread_line().
SPHINXBASE_EXPORT int32 fread_retry | ( | void * | pointer, | |
int32 | size, | |||
int32 | num_items, | |||
FILE * | stream | |||
) |
NFS file reads seem to fail now and then.
Use the following functions in place of the regular fread. It retries failed freads several times and quits only if all of them fail. Be aware, however, that even normal failures such as attempting to read beyond EOF will trigger such retries, wasting about a minute in retries. Arguments identical to regular fread.
Definition at line 322 of file pio.c.
References E_ERROR_SYSTEM, and fread_retry().
Referenced by feat_s2mfc_read(), and fread_retry().
SPHINXBASE_EXPORT int32 stat_retry | ( | const char * | file, | |
struct stat * | statbuf | |||
) |
Like fread_retry, but for stat.
Arguments identical to regular stat. Return value: 0 if successful, -1 if stat failed several attempts.
Definition at line 403 of file pio.c.
References E_ERROR_SYSTEM, and stat_retry().
Referenced by feat_s2mfc_read(), stat_mtime(), and stat_retry().