include/pio.h File Reference

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 bit_encode_s bit_encode_t
 Bitstream encoder - for writing compressed 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_tlineiter_start (FILE *fh)
 Start reading lines from a file.
SPHINXBASE_EXPORT lineiter_tlineiter_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.
bit_encode_tbit_encode_attach (FILE *outfh)
 Attach bitstream encoder to a file.
bit_encode_tbit_encode_retain (bit_encode_t *be)
 Retain pointer to a bit encoder.
int bit_encode_free (bit_encode_t *be)
 Release pointer to a bit encoder.
int bit_encode_write (bit_encode_t *be, unsigned char const *bits, int nbits)
 Write bits to encoder.
int bit_encode_write_cw (bit_encode_t *be, uint32 codeword, int nbits)
 Write lowest-order bits of codeword to encoder.
int bit_encode_flush (bit_encode_t *be)
 Flush any unwritten bits, zero-padding if necessary.
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.


Detailed Description

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.


Function Documentation

int bit_encode_free ( bit_encode_t be  ) 

Release pointer to a bit encoder.

Note that this does NOT flush any leftover bits.

Definition at line 490 of file pio.c.

References bit_encode_free(), ckd_free(), NULL, and bit_encode_s::refcount.

Referenced by bit_encode_free(), and huff_code_detach().

SPHINXBASE_EXPORT void fclose_comp ( FILE *  fp,
int32  ispipe 
)

Close a file opened using fopen_comp.

Parameters:
fp  In: File pointer to be closed
ispipe  In: ispipe argument that was returned by the corresponding fopen_comp() call

Definition at line 165 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).

Parameters:
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 91 of file pio.c.

References ckd_free(), E_ERROR, E_ERROR_SYSTEM, E_FATAL, fopen_comp(), NULL, and string_join().

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

Parameters:
file  In: File to be opened
ispipe  Out: On return *ispipe is TRUE iff file was opened via a pipe

Definition at line 182 of file pio.c.

References ckd_calloc, ckd_free(), E_WARN, fopen_comp(), fopen_compchk(), and NULL.

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.

Deprecated:
Use line iterators instead.
Parameters:
stream The file handle to read from.
out_len Output: if not NULL, length of the string read.
Returns:
allocated string containing the line, or NULL on error or EOF.

Definition at line 300 of file pio.c.

References ckd_malloc, ckd_realloc, fread_line(), and NULL.

Referenced by fread_line(), and huff_code_read().

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 332 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 414 of file pio.c.

References E_ERROR_SYSTEM, and stat_retry().

Referenced by feat_s2mfc_read(), read_cep(), stat_mtime(), and stat_retry().


Generated on Mon Jan 24 21:36:19 2011 for SphinxBase by  doxygen 1.4.7