Bitfile  0.9.2
Bit stream file I/O library
bitfile.h
Go to the documentation of this file.
1 
38 #ifndef _BITFILE_H_
39 #define _BITFILE_H_
40 
67 /***************************************************************************
68 * INCLUDED FILES
69 ***************************************************************************/
70 #include <stdio.h>
71 
72 /***************************************************************************
73 * TYPE DEFINITIONS
74 ***************************************************************************/
75 
81 typedef enum
82 {
83  BF_READ = 0,
84  BF_WRITE = 1,
85  BF_APPEND= 2,
87 } BF_MODES;
88 
89 struct bit_file_t;
90 
96 typedef struct bit_file_t bit_file_t;
97 
98 /***************************************************************************
99 * PROTOTYPES
100 ***************************************************************************/
101 
102 /* open/close file */
103 bit_file_t *BitFileOpen(const char *fileName, const BF_MODES mode);
104 bit_file_t *MakeBitFile(FILE *stream, const BF_MODES mode);
105 int BitFileClose(bit_file_t *stream);
106 FILE *BitFileToFILE(bit_file_t *stream);
107 
108 /* toss spare bits and byte align file */
109 int BitFileByteAlign(bit_file_t *stream);
110 
111 /* fill byte with ones or zeros and write out results */
112 int BitFileFlushOutput(bit_file_t *stream, const unsigned char onesFill);
113 
114 /* get/put character */
115 int BitFileGetChar(bit_file_t *stream);
116 int BitFilePutChar(const int c, bit_file_t *stream);
117 
118 /* get/put single bit */
119 int BitFileGetBit(bit_file_t *stream);
120 int BitFilePutBit(const int c, bit_file_t *stream);
121 
122 /* get/put number of bits (most significant bit to least significat bit) */
123 int BitFileGetBits(bit_file_t *stream, void *bits, const unsigned int count);
124 int BitFilePutBits(bit_file_t *stream, void *bits, const unsigned int count);
125 
126 /***************************************************************************
127 * get/put a number of bits from numerical types (short, int, long, ...)
128 *
129 * For these functions, the first bit in/out is the least significant bit of
130 * the least significant byte, so machine endiness is accounted for. Only
131 * big endian and little endian architectures are currently supported.
132 *
133 * NOTE: size is the sizeof() for the data structure pointed to by bits.
134 ***************************************************************************/
135 int BitFileGetBitsNum(bit_file_t *stream, void *bits, const unsigned int count,
136  const size_t size);
137 int BitFilePutBitsNum(bit_file_t *stream, void *bits, const unsigned int count,
138  const size_t size);
139 
140 #endif /* _BITFILE_H_ */
BF_MODES mode
Definition: bitfile.c:78
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 t...
Definition: bitfile.c:812
Definition: bitfile.h:83
Definition: bitfile.h:84
int BitFileGetBit(bit_file_t *stream)
This function returns the next bit from the file passed as a parameter.
Definition: bitfile.c:625
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 arb...
Definition: bitfile.c:887
bit_file_t * BitFileOpen(const char *fileName, const BF_MODES mode)
This function opens a bit file for reading, writing, or appending.
Definition: bitfile.c:147
bit_file_t * MakeBitFile(FILE *stream, const BF_MODES mode)
This function naively wraps a standard file in a bit_file_t structure.
Definition: bitfile.c:229
int BitFileGetChar(bit_file_t *stream)
This function returns the next byte from the file passed as a parameter.
Definition: bitfile.c:525
int BitFileByteAlign(bit_file_t *stream)
This function aligns the bitfile to the nearest byte.
Definition: bitfile.c:433
Definition: bitfile.h:85
BF_MODES
This is an enumeration of the bit file modes (read, write, and append)
Definition: bitfile.h:81
int BitFileClose(bit_file_t *stream)
This function closes a bit file and frees all associated data.
Definition: bitfile.c:336
int BitFilePutBit(const int c, bit_file_t *stream)
This function writes the bit passed as a parameter to the file passed a parameter.
Definition: bitfile.c:672
int BitFilePutChar(const int c, bit_file_t *stream)
This function writes the byte passed as a parameter to the file passed a parameter.
Definition: bitfile.c:576
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.
Definition: bitfile.c:730
FILE * BitFileToFILE(bit_file_t *stream)
This function flushes and frees the bitfile structure, returning a pointer to a stdio file correspond...
Definition: bitfile.c:382
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 arb...
Definition: bitfile.c:1084
Definition: bitfile.h:86
int BitFileFlushOutput(bit_file_t *stream, const unsigned char onesFill)
This function flushes an output bit buffer.
Definition: bitfile.c:480
This is an complete definition for the type containing data needed to correctly manipulate a bit file...
Definition: bitfile.c:71