Endian-independent binary IO utilities for C
1Bini 2==== 3 4Endian-independent* binary IO utilities for C. 5 6*I only have access to little-endian machines, so it's 7currently untested on big endian, however it *should* 8work. If you have a big endian machine and are willing to 9test that Bini runs as expected, I'd be very grateful. 10 11Bini is written in plain ANSI C. If you're compiling in C99 12or later, functions for reading/writing long long and bool 13will be added automatically. You can override the C version 14Bini sees by passing -Dbini_c=<some year, i.e, 1989, 1999, 152011, etc>. 16 17Usage 18----- 19 20Examples can be found in the </examples/> folder. 21 22I usually run examples with one of these commands: 23 cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && gdb -q -ex=r --args a.out 24 cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && ./a.out &> out.txt 25 26Sample: 27 28 /* Only define this once! You can use the bini.c file to 29 ensure you don't accidentally define bini_impl twice. */ 30 #define bini_impl 31 #include <bini.h> 32 33 int main(void) 34 { 35 /* Allocate a new binary stream. */ 36 struct bini_stream *bs = bini_new(); 37 /* Write the meaning of life, the universe, and everything to our binary stream. */ 38 bini_wi(bs, 42); 39 /* Read the meaning of life, the universe, and everything from our binary stream. */ 40 int life = bini_ri(bs); 41 ASSERT(life == 42); 42 /* Close our stream, flushing+freeing the buffer and the stream itself. */ 43 bini_close(bs); 44 }