Bitfile  0.9.2
Bit stream file I/O library
Data Structures | Typedefs | Enumerations | Functions
Library Code

This module contains the code for the ezini INI file handling library. More...

Data Structures

struct  bit_file_t
 This is an complete definition for the type containing data needed to correctly manipulate a bit file. More...
 
struct  endian_test_t
 This is a union used when testing for endianess. More...
 

Typedefs

typedef int(* num_func_t) (bit_file_t *, void *, const unsigned int, const size_t)
 This type to points to the kind of functions that put/get bits from/to numerical data types (short, int, long, ...) More...
 

Enumerations

enum  endian_t { BF_UNKNOWN_ENDIAN, BF_LITTLE_ENDIAN, BF_BIG_ENDIAN }
 This is an enumeration of the types of endianess handled by this library (big endian and little endian). More...
 

Functions

bit_file_tBitFileOpen (const char *fileName, const BF_MODES mode)
 This function opens a bit file for reading, writing, or appending. More...
 
bit_file_tMakeBitFile (FILE *stream, const BF_MODES mode)
 This function naively wraps a standard file in a bit_file_t structure. More...
 
int BitFileClose (bit_file_t *stream)
 This function closes a bit file and frees all associated data. More...
 
FILE * BitFileToFILE (bit_file_t *stream)
 This function flushes and frees the bitfile structure, returning a pointer to a stdio file corresponding to the bitfile. More...
 
int BitFileByteAlign (bit_file_t *stream)
 This function aligns the bitfile to the nearest byte. More...
 
int BitFileFlushOutput (bit_file_t *stream, const unsigned char onesFill)
 This function flushes an output bit buffer. More...
 
int BitFileGetChar (bit_file_t *stream)
 This function returns the next byte from the file passed as a parameter. More...
 
int BitFilePutChar (const int c, bit_file_t *stream)
 This function writes the byte passed as a parameter to the file passed a parameter. More...
 
int BitFileGetBit (bit_file_t *stream)
 This function returns the next bit from the file passed as a parameter. More...
 
int BitFilePutBit (const int c, bit_file_t *stream)
 This function writes the bit passed as a parameter to the file passed a parameter. More...
 
int BitFileGetBits (bit_file_t *stream, void *bits, const unsigned int count)
 This function reads the specified number of bits from the file passed as a parameter. More...
 
int BitFilePutBits (bit_file_t *stream, void *bits, const unsigned int count)
 This function writes the specified number of bits from the memory location passed as a parameter to the file passed as a parameter. More...
 
int BitFileGetBitsNum (bit_file_t *stream, void *bits, const unsigned int count, const size_t size)
 This function provides a machine independent layer that allows a single function call to stuff an arbitrary number of bits into an integer type variable. More...
 
int BitFilePutBitsNum (bit_file_t *stream, void *bits, const unsigned int count, const size_t size)
 This function provides a machine independent layer that allows a single function call to write an arbitrary number of bits from an integer type variable into a file. More...
 

Detailed Description

This module contains the code for the ezini INI file handling library.

Typedef Documentation

◆ num_func_t

num_func_t

This type to points to the kind of functions that put/get bits from/to numerical data types (short, int, long, ...)

The parameters are a bit file pointer, a pointer to a data structure, the number of bits, and the sizeof the data structure.

Enumeration Type Documentation

◆ endian_t

enum endian_t

This is an enumeration of the types of endianess handled by this library (big endian and little endian).

Enumerator
BF_UNKNOWN_ENDIAN 

unrecognized or untested endianess

BF_LITTLE_ENDIAN 

little endian

BF_BIG_ENDIAN 

big endian

Function Documentation

◆ BitFileByteAlign()

int BitFileByteAlign ( bit_file_t stream)

This function aligns the bitfile to the nearest byte.

Parameters
streamA pointer to the bit file stream to align
Effects
The bit buffer is flushed out.
Returns
EOF if stream is NULL or a write fails. Writes return the byte aligned contents of the bit buffer. Reads returns the unaligned contents of the bit buffer.

This function aligns the bitfile to the nearest byte. For output files, this means writing out the bit buffer with extra bits set to 0. For input files, this means flushing the bit buffer.

Here is the caller graph for this function:

◆ BitFileClose()

int BitFileClose ( bit_file_t stream)

This function closes a bit file and frees all associated data.

Parameters
streamA pointer to the bit file stream being closed.
Effects
The specified file will be closed and the file structure will be freed.
Returns
0 for success or EOF for failure.
Here is the caller graph for this function:

◆ BitFileFlushOutput()

int BitFileFlushOutput ( bit_file_t stream,
const unsigned char  onesFill 
)

This function flushes an output bit buffer.

Parameters
streamA pointer to the bit file stream to flush
onesFillset to non-zero if spare bits are to be filled with ones
Effects
The bit buffer is flushed out. Spare bits are filled with either zeros or ones based on onesFill.
Returns
EOF if stream is NULL or not writable. Otherwise, the bit buffer value written. -1 is returned if no data is written.

This function flushes an output bit buffer. This means left justifying any pending bits, and filling spare bits with the fill value.

◆ BitFileGetBit()

int BitFileGetBit ( bit_file_t stream)

This function returns the next bit from the file passed as a parameter.

Parameters
streamA pointer to the bit file stream to read from
Effects
Reads next bit from bit buffer. If the buffer is empty, a new byte will be read from the file.
Returns
0 if bit == 0, 1 if bit == 1, and EOF if operation fails.

This function returns the next bit from the file passed as a parameter. The bit value returned is the msb in the bit buffer.

Here is the caller graph for this function:

◆ BitFileGetBits()

int BitFileGetBits ( bit_file_t stream,
void *  bits,
const unsigned int  count 
)

This function reads the specified number of bits from the file passed as a parameter.

Parameters
streamA pointer to the bit file stream to read from
bitsThe address to store bits read
countThe number of bits to read
Effects
Reads bits from the bit buffer and file stream. The bit buffer will be modified as necessary.
Returns
EOF for failure, otherwise the number of bits read. If an EOF is reached before all the bits are read, bits will contain every bit through the last complete byte.

This function reads the specified number of bits from the file passed as a parameter and writes them to the specified memory location (ms bit to ls bit).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BitFileGetBitsNum()

int BitFileGetBitsNum ( bit_file_t stream,
void *  bits,
const unsigned int  count,
const size_t  size 
)

This function provides a machine independent layer that allows a single function call to stuff an arbitrary number of bits into an integer type variable.

Parameters
streamA pointer to the bit file stream to read from
bitsThe address to store bits read
countThe number of bits to read
sizesizeof type containing bits
Effects
Calls a function that reads bits from the bit buffer and file stream. The bit buffer will be modified as necessary. The bits will be written to bits from least significant byte to most significant byte.
Returns
EOF for failure, -ENOTSUP for unsupported architecture, otherwise the number of bits read by the called function.
Here is the caller graph for this function:

◆ BitFileGetChar()

int BitFileGetChar ( bit_file_t stream)

This function returns the next byte from the file passed as a parameter.

Parameters
streamA pointer to the bit file stream to read from
Effects
Reads next byte from file and updates the pointer file and bit buffer accordingly.
Returns
EOF if a whole byte cannot be obtained. Otherwise, the character read.
Here is the caller graph for this function:

◆ BitFileOpen()

bit_file_t * BitFileOpen ( const char *  fileName,
const BF_MODES  mode 
)

This function opens a bit file for reading, writing, or appending.

Parameters
fileNameA pointer to a NULL terminated string containing the name of the file to be opened.
modeThe mode of the file to be opened (BF_READ, BF_WRITE, or BF_APPEND).
Effects
The specified file will be opened and file structure will be allocated.
Returns
A pointer to the bit_file_t structure for the bit file opened, or NULL on failure. errno will be set for all failure cases.

This function opens a bit file for reading, writing, or appending. If successful, a bit_file_t data structure will be allocated and a pointer to the structure will be returned.

Here is the caller graph for this function:

◆ BitFilePutBit()

int BitFilePutBit ( const int  c,
bit_file_t stream 
)

This function writes the bit passed as a parameter to the file passed a parameter.

Parameters
cThe bit value to write
streamA pointer to the bit file stream to write to
Effects
Writes a bit to the bit buffer. If the buffer has a byte, the buffer is written to the file and cleared.
Returns
The bit value written is returned on success. EOF is returned on failure.
Here is the caller graph for this function:

◆ BitFilePutBits()

BitFilePutBits ( bit_file_t stream,
void *  bits,
const unsigned int  count 
)

This function writes the specified number of bits from the memory location passed as a parameter to the file passed as a parameter.

Parameters
streamA pointer to the bit file stream to write to
bitsThe address to store bits write
countThe number of bits to write
Effects
Writes bits to the bit buffer and file stream. The bit buffer will be modified as necessary.
Returns
EOF for failure, otherwise the number of bits read. If an EOF is reached before all the bits are read, bits will contain every bit through the last complete byte.

This function writes the specified number of bits from the memory location passed as a parameter to the file passed as a parameter. Bits are written ms bit to ls bit.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BitFilePutBitsNum()

int BitFilePutBitsNum ( bit_file_t stream,
void *  bits,
const unsigned int  count,
const size_t  size 
)

This function provides a machine independent layer that allows a single function call to write an arbitrary number of bits from an integer type variable into a file.

Parameters
streamA pointer to the bit file stream to write to
bitsThe address to store bits to write
countThe number of bits to write
sizesizeof type containing bits
Effects
Calls a function that writes bits to the bit buffer and file stream. The bit buffer will be modified as necessary. The bits will be written to the file stream from least significant byte to most significant byte.
Returns
EOF for failure, -ENOTSUP for unsupported architecture, otherwise the number of bits written. If an error occurs after a partial write, the partially written bits will not be unwritten.
Here is the caller graph for this function:

◆ BitFilePutChar()

int BitFilePutChar ( const int  c,
bit_file_t stream 
)

This function writes the byte passed as a parameter to the file passed a parameter.

Parameters
cThe character to write
streamA pointer to the bit file stream to write to
Effects
Writes c to the file and updates the pointer file and bit buffer accordingly.
Returns
The character written is returned on success. EOF is returned on failure.
Here is the caller graph for this function:

◆ BitFileToFILE()

FILE * BitFileToFILE ( bit_file_t stream)

This function flushes and frees the bitfile structure, returning a pointer to a stdio file corresponding to the bitfile.

Parameters
streamA pointer to the bit file stream being converted
Effects
None
Returns
A FILE pointer to stream. NULL for failure.
Here is the caller graph for this function:

◆ MakeBitFile()

bit_file_t * MakeBitFile ( FILE *  stream,
const BF_MODES  mode 
)

This function naively wraps a standard file in a bit_file_t structure.

Parameters
streamA pointer to the standard file being wrapped.
modeThe mode of the file being wrapped (BF_READ, BF_WRITE, or BF_APPEND).
Effects
A bit_file_t structure will be created for the stream passed as a parameter.
Returns
Pointer to the bit_file_t structure for the bit file or NULL on failure. errno will be set for all failure cases.

This function naively wraps a standard file in a bit_file_t structure. ANSI-C doesn't support file status functions commonly found in other C variants, so the caller must be passed as a parameter.