Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/storage.c')
-rw-r--r--source/blender/blenlib/intern/storage.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index f7a8664c739..a107c84d4d0 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -287,6 +287,39 @@ bool BLI_is_file(const char *path)
return (mode && !S_ISDIR(mode));
}
+void *BLI_file_read_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
+{
+ FILE *fp = BLI_fopen(filepath, "r");
+ void *mem = NULL;
+
+ if (fp) {
+ fseek(fp, 0L, SEEK_END);
+ const long int filelen = ftell(fp);
+ if (filelen == -1) {
+ goto finally;
+ }
+ fseek(fp, 0L, SEEK_SET);
+
+ mem = MEM_mallocN(filelen + pad_bytes, __func__);
+ if (mem == NULL) {
+ goto finally;
+ }
+
+ if (fread(mem, 1, filelen, fp) != filelen) {
+ MEM_freeN(mem);
+ mem = NULL;
+ goto finally;
+ }
+
+ *r_size = filelen;
+ }
+
+finally:
+ fclose(fp);
+ return mem;
+}
+
+
/**
* Reads the contents of a text file and returns the lines in a linked list.
*/