diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 47 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 12 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 31 |
3 files changed, 50 insertions, 40 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 3a2efbd6feb..fef102d8267 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -65,7 +65,8 @@ return -1 if zlib fails, -2 if the originating file does not exist note: will remove the "from" file */ -int BLI_gzip(const char *from, const char *to) { +int BLI_file_gzip(const char *from, const char *to) +{ char buffer[10240]; int file; int readsize = 0; @@ -109,7 +110,7 @@ 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 */ -char *BLI_ungzip_to_mem(const char *from_file, int *size_r) +char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) { gzFile gzfile; int readsize, size, alloc_size=0; @@ -150,7 +151,7 @@ char *BLI_ungzip_to_mem(const char *from_file, int *size_r) /* return 1 when file can be written */ -int BLI_is_writable(const char *filename) +int BLI_file_is_writable(const char *filename) { int file; @@ -178,7 +179,7 @@ int BLI_is_writable(const char *filename) } } -int BLI_touch(const char *file) +int BLI_file_touch(const char *file) { FILE *f = fopen(file,"r+b"); if (f != NULL) { @@ -199,7 +200,8 @@ int BLI_touch(const char *file) static char str[MAXPATHLEN+12]; -int BLI_delete(const char *file, int dir, int recursive) { +int BLI_delete(const char *file, int dir, int recursive) +{ int err; if (recursive) { @@ -216,7 +218,8 @@ int BLI_delete(const char *file, int dir, int recursive) { return err; } -int BLI_move(const char *file, const char *to) { +int BLI_move(const char *file, const char *to) +{ int err; // windows doesn't support moveing to a directory @@ -241,7 +244,8 @@ int BLI_move(const char *file, const char *to) { } -int BLI_copy_fileops(const char *file, const char *to) { +int BLI_copy(const char *file, const char *to) +{ int err; // windows doesn't support copying to a directory @@ -266,14 +270,16 @@ int BLI_copy_fileops(const char *file, const char *to) { return err; } -int BLI_link(const char *file, const char *to) { +int BLI_create_symlink(const char *file, const char *to) +{ callLocalErrorCallBack("Linking files is unsupported on Windows"); (void)file; (void)to; return 1; } -void BLI_recurdir_fileops(const char *dirname) { +void BLI_dir_create_recursive(const char *dirname) +{ char *lslash; char tmp[MAXPATHLEN]; @@ -295,7 +301,7 @@ void BLI_recurdir_fileops(const char *dirname) { if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; - BLI_recurdir_fileops(tmp); + BLI_dir_create_recursive(tmp); } if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ @@ -303,7 +309,8 @@ void BLI_recurdir_fileops(const char *dirname) { callLocalErrorCallBack("Unable to create directory\n"); } -int BLI_rename(const char *from, const char *to) { +int BLI_rename(const char *from, const char *to) +{ if (!BLI_exists(from)) return 0; /* make sure the filenames are different (case insensitive) before removing */ @@ -343,25 +350,29 @@ int BLI_delete(const char *file, int dir, int recursive) return -1; } -int BLI_move(const char *file, const char *to) { +int BLI_move(const char *file, const char *to) +{ BLI_snprintf(str, sizeof(str), "/bin/mv -f \"%s\" \"%s\"", file, to); return system(str); } -int BLI_copy_fileops(const char *file, const char *to) { +int BLI_copy(const char *file, const char *to) +{ BLI_snprintf(str, sizeof(str), "/bin/cp -rf \"%s\" \"%s\"", file, to); return system(str); } -int BLI_link(const char *file, const char *to) { +int BLI_create_symlink(const char *file, const char *to) +{ BLI_snprintf(str, sizeof(str), "/bin/ln -f \"%s\" \"%s\"", file, to); return system(str); } -void BLI_recurdir_fileops(const char *dirname) { +void BLI_dir_create_recursive(const char *dirname) +{ char *lslash; char tmp[MAXPATHLEN]; @@ -373,13 +384,14 @@ void BLI_recurdir_fileops(const char *dirname) { if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; - BLI_recurdir_fileops(tmp); + BLI_dir_create_recursive(tmp); } mkdir(dirname, 0777); } -int BLI_rename(const char *from, const char *to) { +int BLI_rename(const char *from, const char *to) +{ if (!BLI_exists(from)) return 0; if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1; @@ -388,3 +400,4 @@ int BLI_rename(const char *from, const char *to) { } #endif + diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 91e813a0350..d9176c5f162 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -46,8 +46,6 @@ #include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" -#include "BLI_storage.h" -#include "BLI_storage_types.h" #include "BLI_utildefines.h" #include "BKE_utildefines.h" @@ -740,7 +738,7 @@ int BLI_path_cwd(char *path) if (wasrelative==1) { char cwd[FILE_MAXDIR + FILE_MAXFILE]= ""; - BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */ + BLI_current_working_dir(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */ if (cwd[0] == '\0') { printf( "Could not get the current working directory - $PWD for an unknown reason."); @@ -986,7 +984,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } /* try CWD/release/folder_name */ - if(BLI_getwdN(cwd, sizeof(cwd))) { + if(BLI_current_working_dir(cwd, sizeof(cwd))) { if(test_path(targetpath, cwd, "release", relfolder)) { return 1; } @@ -1117,7 +1115,7 @@ char *BLI_get_folder_create(int folder_id, const char *subfolder) if (!path) { path = BLI_get_user_folder_notest(folder_id, subfolder); - if (path) BLI_recurdir_fileops(path); + if (path) BLI_dir_create_recursive(path); } return path; @@ -1250,7 +1248,7 @@ void BLI_make_existing_file(const char *name) /* test exist */ if (BLI_exists(di) == 0) { - BLI_recurdir_fileops(di); + BLI_dir_create_recursive(di); } } @@ -1732,7 +1730,7 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name BLI_strncpy(fullname, name, maxlen); if (name[0] == '.') { char wdir[FILE_MAX]= ""; - BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */ + BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name if(name[1]==SEP) diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 8b383f5fd11..b3caeb71822 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -88,10 +88,9 @@ #include "DNA_listBase.h" +#include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_linklist.h" -#include "BLI_storage.h" -#include "BLI_storage_types.h" #include "BLI_string.h" #include "BKE_utildefines.h" @@ -104,7 +103,7 @@ static struct ListBase dirbase_={NULL, NULL}; static struct ListBase *dirbase = &dirbase_; /* can return NULL when the size is not big enough */ -char *BLI_getwdN(char *dir, const int maxncpy) +char *BLI_current_working_dir(char *dir, const int maxncpy) { const char *pwd= getenv("PWD"); if (pwd){ @@ -116,7 +115,7 @@ char *BLI_getwdN(char *dir, const int maxncpy) } -int BLI_compare(struct direntry *entry1, struct direntry *entry2) +static int bli_compare(struct direntry *entry1, struct direntry *entry2) { /* type is equal to stat.st_mode */ @@ -143,7 +142,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2) } -double BLI_diskfree(const char *dir) +double BLI_dir_free_space(const char *dir) { #ifdef WIN32 DWORD sectorspc, bytesps, freec, clusters; @@ -198,7 +197,7 @@ double BLI_diskfree(const char *dir) #endif } -void BLI_builddir(const char *dirname, const char *relname) +static void bli_builddir(const char *dirname, const char *relname) { struct dirent *fname; struct dirlink *dlink; @@ -273,7 +272,7 @@ void BLI_builddir(const char *dirname, const char *relname) } BLI_freelist(dirbase); - if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))BLI_compare); + if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))bli_compare); } else { printf("%s empty directory\n",dirname); } @@ -284,7 +283,7 @@ void BLI_builddir(const char *dirname, const char *relname) } } -void BLI_adddirstrings(void) +static void bli_adddirstrings(void) { char datum[100]; char buf[512]; @@ -392,7 +391,7 @@ void BLI_adddirstrings(void) } } -unsigned int BLI_getdir(const char *dirname, struct direntry **filelist) +unsigned int BLI_dir_contents(const char *dirname, struct direntry **filelist) { // reset global variables // memory stored in files is free()'d in @@ -401,8 +400,8 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist) actnum = totnum = 0; files = NULL; - BLI_builddir(dirname,""); - BLI_adddirstrings(); + bli_builddir(dirname,""); + bli_adddirstrings(); if (files) { *(filelist) = files; @@ -416,7 +415,7 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist) } -size_t BLI_filesize(int file) +size_t BLI_file_descriptor_size(int file) { struct stat buf; @@ -425,14 +424,14 @@ size_t BLI_filesize(int file) return (buf.st_size); } -size_t BLI_filepathsize(const char *path) +size_t BLI_file_size(const char *path) { int size, file = open(path, O_BINARY|O_RDONLY); if (file == -1) return -1; - size = BLI_filesize(file); + size = BLI_file_descriptor_size(file); close(file); return size; } @@ -474,7 +473,7 @@ int BLI_is_dir(const char *file) return S_ISDIR(BLI_exists(file)); } -LinkNode *BLI_read_file_as_lines(const char *name) +LinkNode *BLI_file_read_as_lines(const char *name) { FILE *fp= fopen(name, "r"); LinkNode *lines= NULL; @@ -515,7 +514,7 @@ LinkNode *BLI_read_file_as_lines(const char *name) return lines; } -void BLI_free_file_lines(LinkNode *lines) +void BLI_file_free_lines(LinkNode *lines) { BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN); } |