summaryrefslogtreecommitdiff
path: root/src/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h
index 1c80ab8..27d8404 100644
--- a/src/common.h
+++ b/src/common.h
@@ -27,4 +27,34 @@ void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
+#define F_LOAD_FILE_ALIGNED(T) \
+ static int load_file_##T##_aligned( \
+ char *path, size_t *size, u32 *buf) \
+ { \
+ int ret = 1; \
+ \
+ FILE *fp = fopen(path, "rb"); \
+ if(!fp) { \
+ err("fopen: %s: %s", path, strerror(errno)); \
+ return 1; \
+ } \
+ \
+ fseek(fp, 0, SEEK_END); \
+ *size = (size_t)ftell(fp); \
+ *size += (*size % sizeof(u32)); \
+ \
+ if(buf == NULL) { \
+ ret = 0; \
+ goto exit; \
+ } \
+ \
+ fseek(fp, 0, SEEK_SET); \
+ fread(buf, sizeof(u32), *size/sizeof(u32), fp); \
+ \
+ return 0; \
+ exit: \
+ fclose(fp); \
+ return ret; \
+ }
+
#endif