summaryrefslogtreecommitdiff
path: root/src/common.h
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-10-20 19:31:31 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-10-20 19:31:31 +0300
commit5115eb592d1477b355770eee9d6b913481d4859f (patch)
treebad0ddf43cea533a91bd1fa36caf6942f1c97b21 /src/common.h
parent22128c747e0817f09c11b004016e6d7c518c1523 (diff)
graphics pipeline
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