···11+Bini
22+====
33+44+Endian-independent* binary IO utilities for C.
55+66+*I only have access to little-endian machines, so it's
77+currently untested on big endian, however it *should*
88+work. If you have a big endian machine and are willing to
99+test that Bini runs as expected, I'd be very grateful.
1010+1111+Bini is written in plain ANSI C. If you're compiling in C99
1212+or later, functions for reading/writing long long and bool
1313+will be added automatically. You can override the C version
1414+Bini sees by passing -Dbini_c=<some year, i.e, 1989, 1999,
1515+2011, etc>.
1616+1717+Usage
1818+-----
1919+2020+Examples can be found in the </examples/> folder.
2121+2222+I usually run examples with one of these commands:
2323+ cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && gdb -q -ex=r --args a.out
2424+ cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && ./a.out &> out.txt
2525+2626+Sample:
2727+2828+ /* Only define this once! You can use the bini.c file to
2929+ ensure you don't accidentally define bini_impl twice. */
3030+ #define bini_impl
3131+ #include <bini.h>
3232+3333+ int main(void)
3434+ {
3535+ /* Allocate a new binary stream. */
3636+ struct bini_stream *bs = bini_new();
3737+ /* Write the meaning of life, the universe, and everything to our binary stream. */
3838+ bini_wi(bs, 42);
3939+ /* Read the meaning of life, the universe, and everything from our binary stream. */
4040+ int life = bini_ri(bs);
4141+ ASSERT(life == 42);
4242+ /* Close our stream, flushing+freeing the buffer and the stream itself. */
4343+ bini_close(bs);
4444+ }