Endian-independent binary IO utilities for C
C 89.3%
Other 10.7%
1 1 0

Clone this repository

https://tangled.org/emmeline.girlkisser.top/bini
git@knot.girlkisser.top:emmeline.girlkisser.top/bini

For self-hosted knots, clone URLs may differ based on your setup.

readme
Bini
====

Endian-independent* binary IO utilities for C.

*I only have access to little-endian machines, so it's
currently untested on big endian, however it *should*
work. If you have a big endian machine and are willing to
test that Bini runs as expected, I'd be very grateful.

Bini is written in plain ANSI C. If you're compiling in C99
or later, functions for reading/writing long long and bool
will be added automatically. You can override the C version
Bini sees by passing -Dbini_c=<some year, i.e, 1989, 1999,
2011, etc>.

Usage
-----

Examples can be found in the </examples/> folder.

I usually run examples with one of these commands:
  cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && gdb -q -ex=r --args a.out
  cc examples/<example>.c -I. -g -Dbini_dbg -Dx_writebin && ./a.out &> out.txt

Sample:

  /* Only define this once! You can use the bini.c file to
     ensure you don't accidentally define bini_impl twice. */
  #define bini_impl
  #include <bini.h>

  int main(void)
  {
    /* Allocate a new binary stream. */
    struct bini_stream *bs = bini_new();
    /* Write the meaning of life, the universe, and everything to our binary stream. */
    bini_wi(bs, 42);
    /* Read the meaning of life, the universe, and everything from our binary stream. */
    int life = bini_ri(bs);
    ASSERT(life == 42);
    /* Close our stream, flushing+freeing the buffer and the stream itself. */
    bini_close(bs);
  }