28 lines
521 B
C
28 lines
521 B
C
#ifndef UTILS_
|
|
#define UTILS_
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <sys/stat.h>
|
|
|
|
uint64_t get_file_size(const char *filename) {
|
|
struct stat result;
|
|
stat(filename, &result);
|
|
return result.st_size;
|
|
}
|
|
|
|
static void alloc_buffer(bool should_alloc, uint8_t **buffer, uint64_t buffer_size) {
|
|
if (should_alloc) {
|
|
*buffer = malloc(sizeof(uint8_t) * buffer_size);
|
|
}
|
|
}
|
|
|
|
static void free_buffer(bool should_alloc, uint8_t *buffer) {
|
|
if (should_alloc) {
|
|
free(buffer);
|
|
}
|
|
}
|
|
|
|
#endif //UTILS_
|