diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_storage.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 9 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 22 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 2 |
6 files changed, 22 insertions, 20 deletions
diff --git a/source/blender/blenlib/BLI_storage.h b/source/blender/blenlib/BLI_storage.h index 0996b19a854..702112f5fec 100644 --- a/source/blender/blenlib/BLI_storage.h +++ b/source/blender/blenlib/BLI_storage.h @@ -44,7 +44,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2); size_t BLI_filesize(int file); size_t BLI_filepathsize(const char *path); double BLI_diskfree(const char *dir); -char *BLI_getwdN(const char *dir); +char *BLI_getwdN(char *dir, const int maxncpy); unsigned int BLI_getdir(const char *dirname, struct direntry **filelist); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 01ad70c31fb..1427a6c651a 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -74,7 +74,7 @@ char *BLI_strdupcat(const char *str1, const char *str2); * the size of dst) * @retval Returns dst */ -char *BLI_strncpy(char *dst, const char *src, int maxncpy); +char *BLI_strncpy(char *dst, const char *src, const int maxncpy); /* Makes a copy of the text within the "" that appear after some text 'blahblah' * i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples" diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index ccda9c17d43..140b424bf8f 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -169,6 +169,11 @@ # define UNUSED(x) UNUSED_ ## x #endif +#ifdef __GNUC__ +# define WARN_UNUSED __attribute__((warn_unused_result)) +#else +# define WARN_UNUSED +#endif /*little macro so inline keyword works*/ #if defined(_MSC_VER) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 5d68fbe6e92..eae50b309b1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -752,8 +752,8 @@ int BLI_path_cwd(char *path) #endif if (wasrelative==1) { - char cwd[FILE_MAXDIR + FILE_MAXFILE]; - BLI_getwdN(cwd); /* incase the full path to the blend isnt used */ + char cwd[FILE_MAXDIR + FILE_MAXFILE]= ""; + BLI_getwdN(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."); @@ -979,7 +979,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } /* try CWD/release/folder_name */ - if(test_path(targetpath, BLI_getwdN(cwd), "release", relfolder)) + if(test_path(targetpath, BLI_getwdN(cwd, sizeof(cwd)), "release", relfolder)) return 1; /* try EXECUTABLE_DIR/release/folder_name */ @@ -1645,6 +1645,7 @@ static int add_win32_extension(char *name) return (retval); } +/* filename must be FILE_MAX length minimum */ void BLI_where_am_i(char *fullname, const char *name) { char filename[FILE_MAXDIR+FILE_MAXFILE]; @@ -1681,7 +1682,7 @@ void BLI_where_am_i(char *fullname, const char *name) strcpy(fullname, name); if (name[0] == '.') { // relative path, prepend cwd - BLI_getwdN(fullname); + BLI_getwdN(fullname, FILE_MAX); // not needed but avoids annoying /./ in name if(name && name[0]=='.' && name[1]==slash) diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index e407df7e9a1..eaa312b82f9 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -89,6 +89,7 @@ #include "BLI_listbase.h" #include "BLI_linklist.h" +#include "BLI_storage.h" #include "BLI_storage_types.h" #include "BLI_string.h" @@ -103,20 +104,15 @@ static struct ListBase dirbase_={ static struct ListBase *dirbase = &dirbase_; -char *BLI_getwdN(char *dir) +char *BLI_getwdN(char *dir, const int maxncpy) { - char *pwd; - - if (dir) { - pwd = getenv("PWD"); - if (pwd){ - strcpy(dir, pwd); - return(dir); - } - /* 160 is FILE_MAXDIR in filesel.c */ - return( getcwd(dir, 160) ); + const char *pwd= getenv("PWD"); + if (pwd){ + BLI_strncpy(dir, pwd, maxncpy); + return dir; } - return(0); + + return getcwd(dir, maxncpy); } @@ -477,7 +473,7 @@ int BLI_is_dir(const char *file) { return S_ISDIR(BLI_exist(file)); } -LinkNode *BLI_read_file_as_lines(char *name) +LinkNode *BLI_read_file_as_lines(const char *name) { FILE *fp= fopen(name, "r"); LinkNode *lines= NULL; diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 6afc34ba630..d6331d6eeb8 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -66,7 +66,7 @@ char *BLI_strdupcat(const char *str1, const char *str2) return n; } -char *BLI_strncpy(char *dst, const char *src, int maxncpy) { +char *BLI_strncpy(char *dst, const char *src, const int maxncpy) { int srclen= strlen(src); int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen; |