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/fileops.c')
-rw-r--r--source/blender/blenlib/intern/fileops.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 7c2b9f03c60..6b125435b31 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -52,6 +52,8 @@
#include <sys/param.h>
#endif
+#include "MEM_guardedalloc.h"
+
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
@@ -107,18 +109,39 @@ int BLI_gzip(const char *from, const char *to) {
/* gzip the file in from_file and write it to memery to_mem, at most size bytes.
return the unziped size
*/
-int BLI_ungzip_to_mem(const char *from_file, char *to_mem, const int size)
+char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
{
gzFile gzfile;
- int readsize;
+ int readsize, size, alloc_size=0;
+ char *mem= NULL;
+ const int chunk_size= 512*1024;
+
+ size= 0;
gzfile = gzopen( from_file, "rb" );
- readsize = gzread( gzfile, to_mem, size);
- if (readsize < 0)
- readsize = EOF;
+ for(;;) {
+ if(mem==NULL) {
+ mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem");
+ alloc_size= chunk_size;
+ } else {
+ mem= MEM_reallocN(mem, size+chunk_size);
+ alloc_size+= chunk_size;
+ }
+
+ readsize= gzread(gzfile, mem+size, chunk_size);
+ if(readsize>0) {
+ size+= readsize;
+ }
+ else break;
+ }
+
+ if(mem && alloc_size!=size)
+ mem= MEM_reallocN(mem, size);
+
+ *size_r= size;
- return readsize;
+ return mem;
}