FreeCalypso > hg > gsm-codec-lib
comparison libtest/binreader.c @ 10:820d88b97924
libtest: implement binary file reader
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 19 Nov 2022 23:57:42 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:4229247843c0 | 10:820d88b97924 |
|---|---|
| 1 /* | |
| 2 * Here we implement our binfile_read_frame() function. | |
| 3 */ | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 #include <stdint.h> | |
| 7 #include "binreader.h" | |
| 8 | |
| 9 int binfile_read_frame(FILE *binf, uint8_t *frame) | |
| 10 { | |
| 11 int cc, morelen; | |
| 12 | |
| 13 cc = fread(frame, 1, 1, binf); | |
| 14 if (cc != 1) | |
| 15 return 0; | |
| 16 if (frame[0] == 0xBF) | |
| 17 morelen = 1; | |
| 18 else if ((frame[0] & 0xF0) == 0xC0) | |
| 19 morelen = 30; | |
| 20 else if ((frame[0] & 0xF0) == 0xD0) | |
| 21 morelen = 32; | |
| 22 else | |
| 23 return -1; | |
| 24 cc = fread(frame+1, 1, morelen, binf); | |
| 25 if (cc == morelen) | |
| 26 return 1; | |
| 27 else | |
| 28 return -2; | |
| 29 } |
