Bitfile
0.9.2
Bit stream file I/O library
|
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_t * | BitFileOpen (const char *fileName, const BF_MODES mode) |
This function opens a bit file for reading, writing, or appending. More... | |
bit_file_t * | MakeBitFile (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... | |
This module contains the code for the ezini INI file handling library.
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.
enum endian_t |
int BitFileByteAlign | ( | bit_file_t * | stream | ) |
This function aligns the bitfile to the nearest byte.
stream | A pointer to the bit file stream to align |
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.
int BitFileClose | ( | bit_file_t * | stream | ) |
This function closes a bit file and frees all associated data.
stream | A pointer to the bit file stream being closed. |
EOF
for failure. int BitFileFlushOutput | ( | bit_file_t * | stream, |
const unsigned char | onesFill | ||
) |
This function flushes an output bit buffer.
stream | A pointer to the bit file stream to flush |
onesFill | set to non-zero if spare bits are to be filled with ones |
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.
int BitFileGetBit | ( | bit_file_t * | stream | ) |
This function returns the next bit from the file passed as a parameter.
stream | A pointer to the bit file stream to read from |
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.
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.
stream | A pointer to the bit file stream to read from |
bits | The address to store bits read |
count | The number of bits to read |
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).
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.
stream | A pointer to the bit file stream to read from |
bits | The address to store bits read |
count | The number of bits to read |
size | sizeof type containing bits |
bits
from least significant byte to most significant byte.EOF
for failure, -ENOTSUP
for unsupported architecture, otherwise the number of bits read by the called function. int BitFileGetChar | ( | bit_file_t * | stream | ) |
This function returns the next byte from the file passed as a parameter.
stream | A pointer to the bit file stream to read from |
EOF
if a whole byte cannot be obtained. Otherwise, the character read. bit_file_t * BitFileOpen | ( | const char * | fileName, |
const BF_MODES | mode | ||
) |
This function opens a bit file for reading, writing, or appending.
fileName | A pointer to a NULL terminated string containing the name of the file to be opened. |
mode | The mode of the file to be opened (BF_READ, BF_WRITE, or BF_APPEND). |
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.
int BitFilePutBit | ( | const int | c, |
bit_file_t * | stream | ||
) |
This function writes the bit passed as a parameter to the file passed a parameter.
c | The bit value to write |
stream | A pointer to the bit file stream to write to |
EOF
is returned on failure. 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.
stream | A pointer to the bit file stream to write to |
bits | The address to store bits write |
count | The number of bits to write |
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.
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.
stream | A pointer to the bit file stream to write to |
bits | The address to store bits to write |
count | The number of bits to write |
size | sizeof type containing bits |
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. int BitFilePutChar | ( | const int | c, |
bit_file_t * | stream | ||
) |
This function writes the byte passed as a parameter to the file passed a parameter.
c | The character to write |
stream | A pointer to the bit file stream to write to |
EOF
is returned on failure. 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.
stream | A pointer to the bit file stream being converted |
NULL
for failure. bit_file_t * MakeBitFile | ( | FILE * | stream, |
const BF_MODES | mode | ||
) |
This function naively wraps a standard file in a bit_file_t structure.
stream | A pointer to the standard file being wrapped. |
mode | The mode of the file being wrapped (BF_READ, BF_WRITE, or BF_APPEND). |
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.