diff options
author | yenatch <yenatch@gmail.com> | 2018-03-10 18:01:54 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2018-03-10 18:53:04 -0500 |
commit | f75049feef17757cd07eb86cf34729c272cefcd5 (patch) | |
tree | 7297aa8ae7a05b45a60160baa304a7e0088235b7 /tools/common.h | |
parent | 37ded1d150197b3784bc351eeeb0a8d9713c2e35 (diff) |
Use rgbgfx and c tools instead of the submodule.
Diffstat (limited to 'tools/common.h')
-rw-r--r-- | tools/common.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/common.h b/tools/common.h new file mode 100644 index 00000000..4da0b2ef --- /dev/null +++ b/tools/common.h @@ -0,0 +1,40 @@ +#ifndef GUARD_COMMON_H +#define GUARD_COMMON_H + +int __getopt_long_i__; +#define getopt_long(c, v, s, l) getopt_long(c, v, s, l, &__getopt_long_i__) + +FILE *fopen_verbose(char *filename, char *mode) { + FILE *f = fopen(filename, mode); + if (!f) { + fprintf(stderr, "Could not open file: \"%s\"\n", filename); + } + return f; +} + +uint8_t *read_u8(char *filename, int *size) { + FILE *f = fopen_verbose(filename, "rb"); + if (!f) { + exit(1); + } + fseek(f, 0, SEEK_END); + *size = ftell(f); + rewind(f); + uint8_t *data = malloc(*size); + if (*size != (int)fread(data, 1, *size, f)) { + fprintf(stderr, "Could not read file: \"%s\"\n", filename); + exit(1); + } + fclose(f); + return data; +} + +void write_u8(char *filename, uint8_t *data, int size) { + FILE *f = fopen_verbose(filename, "wb"); + if (f) { + fwrite(data, 1, size, f); + fclose(f); + } +} + +#endif // GUARD_COMMON_H |