diff options
Diffstat (limited to 'source/blender/blenlib/intern/fileops.c')
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 0a5e4d9fd48..e6d06484e74 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -74,7 +74,7 @@ int BLI_file_gzip(const char *from, const char *to) char buffer[10240]; int file; int readsize = 0; - int rval= 0, err; + int rval = 0, err; gzFile gzfile; /* level 1 is very close to 3 (the default) in terms of file size, @@ -82,7 +82,7 @@ int BLI_file_gzip(const char *from, const char *to) gzfile = BLI_gzopen(to, "wb1"); if (gzfile == NULL) return -1; - file = BLI_open(from, O_BINARY|O_RDONLY, 0); + file = BLI_open(from, O_BINARY | O_RDONLY, 0); if (file < 0) return -2; @@ -90,15 +90,15 @@ int BLI_file_gzip(const char *from, const char *to) readsize = read(file, buffer, sizeof(buffer)); if (readsize < 0) { - rval= -2; /* error happened in reading */ + rval = -2; /* error happened in reading */ fprintf(stderr, "Error reading file %s: %s.\n", from, strerror(errno)); break; } else if (readsize == 0) - break; /* done reading */ + break; /* done reading */ if (gzwrite(gzfile, buffer, readsize) <= 0) { - rval= -1; /* error happened in writing */ + rval = -1; /* error happened in writing */ fprintf(stderr, "Error writing gz file %s: %s.\n", to, gzerror(gzfile, &err)); break; } @@ -116,38 +116,38 @@ int BLI_file_gzip(const char *from, const char *to) char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) { gzFile gzfile; - int readsize, size, alloc_size=0; - char *mem= NULL; - const int chunk_size= 512*1024; + int readsize, size, alloc_size = 0; + char *mem = NULL; + const int chunk_size = 512 * 1024; - size= 0; + size = 0; - gzfile = BLI_gzopen( from_file, "rb" ); - for (;;) { - if (mem==NULL) { - mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem"); - alloc_size= chunk_size; + gzfile = BLI_gzopen(from_file, "rb"); + 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; + mem = MEM_reallocN(mem, size + chunk_size); + alloc_size += chunk_size; } - readsize= gzread(gzfile, mem+size, chunk_size); - if (readsize>0) { - size+= readsize; + readsize = gzread(gzfile, mem + size, chunk_size); + if (readsize > 0) { + size += readsize; } else break; } - if (size==0) { + if (size == 0) { MEM_freeN(mem); - mem= NULL; + mem = NULL; } - else if (alloc_size!=size) - mem= MEM_reallocN(mem, size); + else if (alloc_size != size) + mem = MEM_reallocN(mem, size); - *size_r= size; + *size_r = size; return mem; } @@ -254,14 +254,14 @@ int BLI_delete(const char *file, int dir, int recursive) if (recursive) { callLocalErrorCallBack("Recursive delete is unsupported on Windows"); - err= 1; + err = 1; } else if (dir) { - err= !RemoveDirectoryW(file_16); - if (err) printf ("Unable to remove directory"); + err = !RemoveDirectoryW(file_16); + if (err) printf("Unable to remove directory"); } else { - err= !DeleteFileW(file_16); + err = !DeleteFileW(file_16); if (err) callLocalErrorCallBack("Unable to delete file"); } @@ -288,7 +288,7 @@ int BLI_move(const char *file, const char *to) UTF16_ENCODE(file); UTF16_ENCODE(str); - err= !MoveFileW(file_16, str_16); + err = !MoveFileW(file_16, str_16); UTF16_UN_ENCODE(str); UTF16_UN_ENCODE(file); @@ -350,7 +350,7 @@ void BLI_dir_create_recursive(const char *dirname) * blah1/blah2 (without slash) */ BLI_strncpy(tmp, dirname, sizeof(tmp)); - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash == tmp + strlen(tmp) - 1) { *lslash = 0; @@ -358,7 +358,7 @@ void BLI_dir_create_recursive(const char *dirname) if (BLI_exists(tmp)) return; - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; @@ -366,7 +366,7 @@ void BLI_dir_create_recursive(const char *dirname) } if (dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ - if (umkdir(dirname)==-1) + if (umkdir(dirname) == -1) printf("Unable to create directory %s\n", dirname); } @@ -394,7 +394,7 @@ enum { recursiveOp_Callback_Error = 2 } recuresiveOp_Callback_Result; -typedef int (*recursiveOp_Callback) (const char *from, const char *to); +typedef int (*recursiveOp_Callback)(const char *from, const char *to); /* appending of filename to dir (ensures for buffer size before appending) */ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, const char *file) @@ -680,11 +680,11 @@ static int copy_single_file(const char *from, const char *to) need_free = 0; } else { - link_buffer = MEM_callocN(st.st_size+2, "copy_single_file link_buffer"); + link_buffer = MEM_callocN(st.st_size + 2, "copy_single_file link_buffer"); need_free = 1; } - link_len = readlink(from, link_buffer, st.st_size+1); + link_len = readlink(from, link_buffer, st.st_size + 1); if (link_len < 0) { perror("readlink"); @@ -706,10 +706,10 @@ static int copy_single_file(const char *from, const char *to) return recursiveOp_Callback_OK; } - else if (S_ISCHR (st.st_mode) || - S_ISBLK (st.st_mode) || - S_ISFIFO (st.st_mode) || - S_ISSOCK (st.st_mode)) + else if (S_ISCHR(st.st_mode) || + S_ISBLK(st.st_mode) || + S_ISFIFO(st.st_mode) || + S_ISSOCK(st.st_mode)) { /* copy special type of file */ if (mknod(to, st.st_mode, st.st_rdev)) { @@ -798,7 +798,7 @@ static char *check_destination(const char *file, const char *to) if (!filename) { MEM_freeN(str); - return (char*)to; + return (char *)to; } /* skip slash */ @@ -814,7 +814,7 @@ static char *check_destination(const char *file, const char *to) } } - return (char*)to; + return (char *)to; } int BLI_copy(const char *file, const char *to) @@ -824,7 +824,7 @@ int BLI_copy(const char *file, const char *to) ret = recursive_operation(file, actual_to, copy_callback_pre, copy_single_file, NULL); - if (actual_to!=to) + if (actual_to != to) MEM_freeN(actual_to); return ret; @@ -852,16 +852,16 @@ void BLI_dir_create_recursive(const char *dirname) tmp = static_buf; needs_free = 0; #else - size = strlen(dirname)+1; + size = strlen(dirname) + 1; tmp = MEM_callocN(size, "BLI_dir_create_recursive tmp"); needs_free = 1; #endif BLI_strncpy(tmp, dirname, size); - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash) { - /* Split about the last slash and recurse */ + /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } |