Last active
January 31, 2020 09:52
-
-
Save xobs/b83fe50e016ee42634e68359d321b621 to your computer and use it in GitHub Desktop.
Read tags from a binary stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdint.h> | |
| #include <sys/stat.h> | |
| #include <fcntl.h> | |
| #include <unistd.h> | |
| int main(int argc, char **argv) { | |
| int f = open("args.bin", O_RDONLY); | |
| uint8_t fourcc[4]; | |
| uint32_t val; | |
| uint32_t size; | |
| int i; | |
| while (1) { | |
| int res; | |
| res = read(f, &fourcc, 4); | |
| if (res != 4) | |
| break; | |
| res = read(f, &size, 4); | |
| if (res != 4) { | |
| fprintf(stderr, "Trailing data\n"); | |
| break; | |
| } | |
| fprintf(stderr, "%c%c%c%c (%d bytes):", fourcc[0], fourcc[1], fourcc[2], fourcc[3], size); | |
| for (i = 0; i < size; i += 4) { | |
| res = read(f, &val, 4); | |
| if (res != 4) { | |
| fprintf(stderr, "Short read!\n"); | |
| break; | |
| } | |
| fprintf(stderr, " %08x", val); | |
| } | |
| fprintf(stderr, "\n"); | |
| } | |
| fprintf(stderr, "\n"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment