-static uint8_t read_uintX_bigendian(FILE * file, uint32_t * x, uint8_t size)
-{
- * x = 0;
- int16_t bitshift = size - 8;
- int test;
- for (; bitshift >= 0; bitshift = bitshift - 8)
- {
- test = fgetc(file);
- if (EOF == test)
- {
- return 1;
- }
- * x = * x + ((uint32_t) test << bitshift);
- }
- return 0;
-}
-
-
-
-static uint8_t write_uintX_bigendian(FILE * file, uint32_t x, uint8_t size)
-{
- int16_t bitshift = size - 8;
- for (; bitshift >= 0; bitshift = bitshift - 8)
- {
- if (EOF == fputc((x >> bitshift) & 0xFF, file))
- {
- return 1;
- }
- }
- return 0;
-}
-
-
-
-extern uint8_t read_uint8(FILE * file, uint8_t * x)
-{
- /* Since read_uintX_bigendian() works on -- and zeroes -- four bytes, direct
- * work on values of fewer bytes would corrupt immediate neighbor values.
- */
- uint32_t y = * x;
- uint8_t err = read_uintX_bigendian(file, &y, 8);
- * x = (uint8_t) y;
- return err;
-}
-
-
-
-extern uint8_t read_uint32_bigendian(FILE * file, uint32_t * x)
-{
- return read_uintX_bigendian(file, x, 32);
-}
-
-
-
-extern uint8_t write_uint8(uint8_t x, FILE * file)