diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-01 06:01:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-01 06:01:09 +0400 |
commit | e08c4a00d230d3a09a8f3ab25256100113db36b7 (patch) | |
tree | 3edb6f5efc008c3f8f623d430a9884846651115b /source/blender/blenlib | |
parent | 1a2188af41b272506e3b58129f178db2172d053f (diff) | |
parent | a5959e767e1fce78fa1876e8791667a377ac51f1 (diff) |
svn merge -r41371:41420 ^/trunk/blender
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_threads.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 47 | ||||
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 5 |
4 files changed, 46 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index dd4bc868ab0..68bb1a7280d 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -102,6 +102,7 @@ int BLI_testextensie(const char *str, const char *ext); int BLI_testextensie_array(const char *str, const char **ext_array); int BLI_testextensie_glob(const char *str, const char *ext_fnmatch); int BLI_replace_extension(char *path, size_t maxlen, const char *ext); +int BLI_ensure_extension(char *path, size_t maxlen, const char *ext); void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len); int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len); void BLI_newname(char * name, int add); diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h index 973bb57bb42..bd911adeba2 100644 --- a/source/blender/blenlib/BLI_threads.h +++ b/source/blender/blenlib/BLI_threads.h @@ -70,7 +70,8 @@ int BLI_system_thread_count(void); /* gets the number of threads the system can #define LOCK_CUSTOM1 3 #define LOCK_RCACHE 4 #define LOCK_OPENGL 5 -#define LOCK_SCANFILL 6 +#define LOCK_NODES 6 +#define LOCK_SCANFILL 7 void BLI_lock_thread(int type); void BLI_unlock_thread(int type); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 4fa2bcd2cb8..ab3de94d77c 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1398,22 +1398,51 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) int BLI_replace_extension(char *path, size_t maxlen, const char *ext) { + size_t path_len= strlen(path); + size_t ext_len= strlen(ext); size_t a; - for(a=strlen(path); a>0; a--) { - if(path[a-1] == '.' || path[a-1] == '/' || path[a-1] == '\\') { - a--; + for(a= path_len - 1; a >= 0; a--) { + if (ELEM3(path[a], '.', '/', '\\')) { break; } } - - if(path[a] != '.') - a= strlen(path); - if(a + strlen(ext) >= maxlen) + if(a + ext_len >= maxlen) + return 0; + + memcpy(path+a, ext, ext_len + 1); + return 1; +} + +/* strip's trailing '.'s and adds the extension only when needed */ +int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) +{ + size_t path_len= strlen(path); + size_t ext_len= strlen(ext); + size_t a; + + /* first check the extension is alread there */ + if ( (ext_len <= path_len) && + (strcmp(path + (path_len - ext_len), ext) == 0)) + { + return 1; + } + + for(a= path_len - 1; a >= 0; a--) { + if (path[a] == '.') { + path[a]= '\0'; + } + else { + break; + } + } + a++; + + if(a + ext_len >= maxlen) return 0; - strcpy(path+a, ext); + memcpy(path+a, ext, ext_len + 1); return 1; } @@ -1845,7 +1874,7 @@ void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir) /* add a trailing slash if needed */ BLI_add_slash(fullname); #ifdef WIN32 - if(userdir != fullname) { + if(userdir && userdir != fullname) { BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */ } #endif diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 37f37887688..f80458682e1 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -113,6 +113,7 @@ static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _rcache_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _opengl_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t _nodes_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _scanfill_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t mainid; static int thread_levels= 0; /* threads can be invoked inside threads */ @@ -348,6 +349,8 @@ void BLI_lock_thread(int type) pthread_mutex_lock(&_rcache_lock); else if (type==LOCK_OPENGL) pthread_mutex_lock(&_opengl_lock); + else if (type==LOCK_NODES) + pthread_mutex_lock(&_nodes_lock); else if (type == LOCK_SCANFILL) pthread_mutex_lock(&_scanfill_lock); } @@ -366,6 +369,8 @@ void BLI_unlock_thread(int type) pthread_mutex_unlock(&_rcache_lock); else if(type==LOCK_OPENGL) pthread_mutex_unlock(&_opengl_lock); + else if(type==LOCK_NODES) + pthread_mutex_unlock(&_nodes_lock); else if(type == LOCK_SCANFILL) pthread_mutex_unlock(&_scanfill_lock); } |