diff options
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 245 |
1 files changed, 139 insertions, 106 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index a512ac746f9..2bbc4517da1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -62,6 +62,7 @@ #endif #ifdef WIN32 +#include "utf_winfunc.h" # include <io.h> # ifdef _WIN32_IE # undef _WIN32_IE @@ -110,18 +111,18 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu short i, found = 0; char *lslash = BLI_last_slash(string); len2 = len = strlen(string); - if(lslash) + if (lslash) lenlslash= (int)(lslash - string); - while(len > lenlslash && string[--len] != '.') {}; - if(len == lenlslash && string[len] != '.') len = len2; + while (len > lenlslash && string[--len] != '.') {}; + if (len == lenlslash && string[len] != '.') len = len2; for (i = len - 1; i >= lenlslash; i--) { if (isdigit(string[i])) { if (found) { nums = i; } - else{ + else { nume = i; nums = i; found = 1; @@ -153,7 +154,7 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) { char fmtstr[16]=""; - if(pic < 0) pic= 0; + if (pic < 0) pic= 0; sprintf(fmtstr, "%%s%%.%dd%%s", numlen); sprintf(string, fmtstr, head, pic, tail); } @@ -168,23 +169,23 @@ int BLI_split_name_num(char *left, int *nr, const char *name, const char delim) a= strlen(name); memcpy(left, name, (a + 1) * sizeof(char)); - if(a>1 && name[a-1]==delim) return a; + if (a>1 && name[a-1]==delim) return a; - while(a--) { - if( name[a]==delim ) { + while (a--) { + if ( name[a]==delim ) { left[a]= 0; *nr= atol(name+a+1); /* casting down to an int, can overflow for large numbers */ - if(*nr < 0) + if (*nr < 0) *nr= 0; return a; } - if( isdigit(name[a])==0 ) break; + if ( isdigit(name[a])==0 ) break; left[a]= 0; } - for(a= 0; name[a]; a++) + for (a= 0; name[a]; a++) left[a]= name[a]; return a; @@ -216,11 +217,11 @@ void BLI_newname(char *name, int add) int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len) { - if(name[0] == '\0') { + if (name[0] == '\0') { BLI_strncpy(name, defname, name_len); } - if(unique_check(arg, name)) { + if (unique_check(arg, name)) { char numstr[16]; char tempname[UNIQUE_NAME_MAX]; char left[UNIQUE_NAME_MAX]; @@ -241,7 +242,7 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons tempname_buf = BLI_strncat_utf8(tempname, left, name_len - numlen); memcpy(tempname_buf, numstr, numlen + 1); } - } while(unique_check(arg, tempname)); + } while (unique_check(arg, tempname)); BLI_strncpy(name, tempname, name_len); @@ -321,7 +322,8 @@ void BLI_cleanup_path(const char *relabase, char *dir) char *start, *eind; if (relabase) { BLI_path_abs(dir, relabase); - } else { + } + else { if (dir[0]=='/' && dir[1]=='/') { if (dir[2]== '\0') { return; /* path is "//" - cant clean it */ @@ -331,7 +333,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) } /* Note - * memmove( start, eind, strlen(eind)+1 ); + * memmove(start, eind, strlen(eind) + 1); * is the same as * strcpy( start, eind ); * except strcpy should not be used because there is overlap, @@ -342,7 +344,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* Note, this should really be moved to the file selector, * since this function is used in many areas */ - if(strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ + if (strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ get_default_root(dir); return; } @@ -356,22 +358,23 @@ void BLI_cleanup_path(const char *relabase, char *dir) } if (a<0) { break; - } else { - memmove( dir+a, eind, strlen(eind)+1 ); + } + else { + memmove(dir + a, eind, strlen(eind) + 1); } } while ( (start = strstr(dir,"\\.\\")) ) { eind = start + strlen("\\.\\") - 1; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } while ( (start = strstr(dir,"\\\\" )) ) { eind = start + strlen("\\\\") - 1; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } #else - if(dir[0]=='.') { /* happens, for example in FILE_MAIN */ + if (dir[0]=='.') { /* happens, for example in FILE_MAIN */ dir[0]= '/'; dir[1]= 0; return; @@ -380,8 +383,8 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* support for odd paths: eg /../home/me --> /home/me * this is a valid path in blender but we cant handle this the usual way below * simply strip this prefix then evaluate the path as usual. pythons os.path.normpath() does this */ - while((strncmp(dir, "/../", 4)==0)) { - memmove( dir, dir + 4, strlen(dir + 4) + 1 ); + while ((strncmp(dir, "/../", 4)==0)) { + memmove(dir, dir + 4, strlen(dir + 4) + 1); } while ( (start = strstr(dir, "/../")) ) { @@ -393,19 +396,20 @@ void BLI_cleanup_path(const char *relabase, char *dir) } if (a<0) { break; - } else { - memmove( dir+a, eind, strlen(eind)+1 ); + } + else { + memmove(dir+a, eind, strlen(eind) + 1); } } while ( (start = strstr(dir,"/./")) ) { eind = start + (3 - 1) /* strlen("/./") - 1 */; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } while ( (start = strstr(dir,"//" )) ) { eind = start + (2 - 1) /* strlen("//") - 1 */; - memmove( start, eind, strlen(eind)+1 ); + memmove(start, eind, strlen(eind) + 1); } #endif } @@ -430,7 +434,7 @@ void BLI_path_rel(char *file, const char *relfile) char res[FILE_MAX]; /* if file is already relative, bail out */ - if(file[0]=='/' && file[1]=='/') return; + if (file[0]=='/' && file[1]=='/') return; /* also bail out if relative path is not set */ if (relfile[0] == 0) return; @@ -446,7 +450,8 @@ void BLI_path_rel(char *file, const char *relfile) ptemp++; } BLI_strncpy(ptemp, relfile, FILE_MAX-3); - } else { + } + else { BLI_strncpy(temp, relfile, FILE_MAX); } @@ -481,7 +486,7 @@ void BLI_path_rel(char *file, const char *relfile) #endif { ++p; ++q; - /* dont search beyond the end of the string + /* don't search beyond the end of the string * in the rare case they match */ if ((*p=='\0') || (*q=='\0')) { break; @@ -547,7 +552,8 @@ int BLI_parent_dir(char *path) if (!BLI_testextensie(tmp, parent_dir)) { BLI_strncpy(path, tmp, sizeof(tmp)); return 1; - } else { + } + else { return 0; } } @@ -559,8 +565,9 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) ch_sta = ch_end = 0; for (i = 0; path[i] != '\0'; i++) { if (path[i] == '\\' || path[i] == '/') { - ch_end = 0; /* this is a directory name, dont use any hashes we found */ - } else if (path[i] == '#') { + ch_end = 0; /* this is a directory name, don't use any hashes we found */ + } + else if (path[i] == '#') { ch_sta = i; ch_end = ch_sta+1; while (path[ch_end] == '#') { @@ -568,11 +575,11 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) } i = ch_end-1; /* keep searching */ - /* dont break, there may be a slash after this that invalidates the previous #'s */ + /* don't break, there may be a slash after this that invalidates the previous #'s */ } } - if(ch_end) { + if (ch_end) { *char_start= ch_sta; *char_end= ch_end; return 1; @@ -588,13 +595,13 @@ static void ensure_digits(char *path, int digits) { char *file= BLI_last_slash(path); - if(file==NULL) + if (file==NULL) file= path; - if(strrchr(file, '#') == NULL) { + if (strrchr(file, '#') == NULL) { int len= strlen(file); - while(digits--) { + while (digits--) { file[len++]= '#'; } file[len]= '\0'; @@ -605,7 +612,7 @@ int BLI_path_frame(char *path, int frame, int digits) { int ch_sta, ch_end; - if(digits) + if (digits) ensure_digits(path, digits); if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ @@ -621,7 +628,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) { int ch_sta, ch_end; - if(digits) + if (digits) ensure_digits(path, digits); if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ @@ -680,7 +687,7 @@ int BLI_path_abs(char *path, const char *basepath) BLI_strncpy(base, basepath, sizeof(base)); - /* file component is ignored, so dont bother with the trailing slash */ + /* file component is ignored, so don't bother with the trailing slash */ BLI_cleanup_path(NULL, base); /* push slashes into unix mode - strings entering this part are @@ -693,7 +700,7 @@ int BLI_path_abs(char *path, const char *basepath) BLI_char_switch(base, '\\', '/'); /* Paths starting with // will get the blend file as their base, - * this isnt standard in any os but is used in blender all over the place */ + * this isn't standard in any os but is used in blender all over the place */ if (wasrelative) { char *lslash= BLI_last_slash(base); if (lslash) { @@ -704,10 +711,12 @@ int BLI_path_abs(char *path, const char *basepath) memcpy(tmp, base, baselen); BLI_strncpy(tmp+baselen, path, sizeof(tmp)-baselen); BLI_strncpy(path, tmp, FILE_MAX); - } else { + } + else { BLI_strncpy(path, tmp+2, FILE_MAX); } - } else { + } + else { BLI_strncpy(path, tmp, FILE_MAX); } @@ -746,16 +755,17 @@ int BLI_path_cwd(char *path) if (wasrelative==1) { char cwd[FILE_MAX]= ""; - BLI_current_working_dir(cwd, sizeof(cwd)); /* in case the full path to the blend isnt used */ + BLI_current_working_dir(cwd, sizeof(cwd)); /* in case the full path to the blend isn't used */ if (cwd[0] == '\0') { printf( "Could not get the current working directory - $PWD for an unknown reason."); - } else { + } + else { /* uses the blend path relative to cwd important for loading relative linked files. * * cwd should contain c:\ etc on win32 so the relbase can be NULL * relbase being NULL also prevents // being misunderstood as relative to the current - * blend file which isnt a feature we want to use in this case since were dealing + * blend file which isn't a feature we want to use in this case since were dealing * with a path from the command line, rather than from inside Blender */ char origpath[FILE_MAX]; @@ -777,7 +787,8 @@ void BLI_splitdirstring(char *di, char *fi) if (lslash) { BLI_strncpy(fi, lslash+1, FILE_MAXFILE); *(lslash+1)=0; - } else { + } + else { BLI_strncpy(fi, di, FILE_MAXFILE); di[0]= 0; } @@ -797,7 +808,8 @@ void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) } if (prevslash) { BLI_strncpy(last, prevslash+1, maxlen); - } else { + } + else { BLI_strncpy(last, dir, maxlen); } } @@ -824,10 +836,8 @@ const char *BLI_getDefaultDocumentFolder(void) HRESULT hResult; /* Check for %HOME% env var */ - - ret = getenv("HOME"); - if(ret) { - if (BLI_is_dir(ret)) return ret; + if (uput_getenv("HOME",documentfolder,MAXPATHLEN)) { + if (BLI_is_dir(documentfolder)) return documentfolder; } /* add user profile support for WIN 2K / NT. @@ -862,11 +872,11 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s { char tmppath[FILE_MAX]; - if(path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); + if (path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); else BLI_strncpy(tmppath, path_base, sizeof(tmppath)); /* rare cases folder_name is omitted (when looking for ~/.blender/2.xx dir only) */ - if(folder_name) + if (folder_name) BLI_make_file_string("/", targetpath, tmppath, folder_name); else BLI_strncpy(targetpath, tmppath, sizeof(tmppath)); @@ -894,7 +904,8 @@ static int test_env_path(char *path, const char *envvar) if (BLI_is_dir(env)) { BLI_strncpy(path, env, FILE_MAX); return 1; - } else { + } + else { path[0] = '\0'; return 0; } @@ -908,10 +919,11 @@ static int get_path_local(char *targetpath, const char *folder_name, const char printf("get_path_local...\n"); #endif - if(folder_name) { + if (folder_name) { if (subfolder_name) { BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name); - } else { + } + else { BLI_strncpy(relfolder, folder_name, sizeof(relfolder)); } } @@ -920,7 +932,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char } /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */ - if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder)) + if (test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder)) return 1; return 0; @@ -949,7 +961,8 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * if (test_env_path(user_path, envvar)) { if (subfolder_name) { return test_path(targetpath, user_path, NULL, subfolder_name); - } else { + } + else { BLI_strncpy(targetpath, user_path, FILE_MAX); return 1; } @@ -960,7 +973,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal(ver)); } - if(!user_path[0]) + if (!user_path[0]) return 0; #ifdef PATH_DEBUG2 @@ -970,7 +983,8 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * if (subfolder_name) { /* try $HOME/folder_name/subfolder_name */ return test_path(targetpath, user_path, folder_name, subfolder_name); - } else { + } + else { /* try $HOME/folder_name */ return test_path(targetpath, user_path, NULL, folder_name); } @@ -987,10 +1001,11 @@ static int get_path_system(char *targetpath, const char *folder_name, const char char cwd[FILE_MAX]; char relfolder[FILE_MAX]; - if(folder_name) { + if (folder_name) { if (subfolder_name) { BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name); - } else { + } + else { BLI_strncpy(relfolder, folder_name, sizeof(relfolder)); } } @@ -999,14 +1014,14 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } /* try CWD/release/folder_name */ - if(BLI_current_working_dir(cwd, sizeof(cwd))) { - if(test_path(targetpath, cwd, "release", relfolder)) { + if (BLI_current_working_dir(cwd, sizeof(cwd))) { + if (test_path(targetpath, cwd, "release", relfolder)) { return 1; } } /* try EXECUTABLE_DIR/release/folder_name */ - if(test_path(targetpath, bprogdir, "release", relfolder)) + if (test_path(targetpath, bprogdir, "release", relfolder)) return 1; /* end developer overrides */ @@ -1017,7 +1032,8 @@ static int get_path_system(char *targetpath, const char *folder_name, const char if (test_env_path(system_path, envvar)) { if (subfolder_name) { return test_path(targetpath, system_path, NULL, subfolder_name); - } else { + } + else { BLI_strncpy(targetpath, system_path, FILE_MAX); return 1; } @@ -1028,7 +1044,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal(ver)); } - if(!system_path[0]) + if (!system_path[0]) return 0; #ifdef PATH_DEBUG2 @@ -1038,7 +1054,8 @@ static int get_path_system(char *targetpath, const char *folder_name, const char if (subfolder_name) { /* try $BLENDERPATH/folder_name/subfolder_name */ return test_path(targetpath, system_path, folder_name, subfolder_name); - } else { + } + else { /* try $BLENDERPATH/folder_name */ return test_path(targetpath, system_path, NULL, folder_name); } @@ -1156,7 +1173,7 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) BLI_assert(!"incorrect ID"); } - if((ok == FALSE) && do_check) { + if ((ok == FALSE) && do_check) { return NULL; } @@ -1185,7 +1202,9 @@ void BLI_setenv(const char *env, const char*val) /* non-free windows */ #elif (defined(WIN32) || defined(WIN64)) /* not free windows */ - _putenv_s(env, val); + uputenv(env, val); + + #else /* linux/osx/bsd */ setenv(env, val, 1); @@ -1199,17 +1218,17 @@ void BLI_setenv(const char *env, const char*val) */ void BLI_setenv_if_new(const char *env, const char* val) { - if(getenv(env) == NULL) + if (getenv(env) == NULL) BLI_setenv(env, val); } void BLI_clean(char *path) { - if(path==NULL) return; + if (path==NULL) return; #ifdef WIN32 - if(path && BLI_strnlen(path, 3) > 2) { + if (path && BLI_strnlen(path, 3) > 2) { BLI_char_switch(path+2, '/', '\\'); } #else @@ -1219,7 +1238,7 @@ void BLI_clean(char *path) void BLI_char_switch(char *string, char from, char to) { - if(string==NULL) return; + if (string==NULL) return; while (*string != 0) { if (*string == from) *string = to; string++; @@ -1302,7 +1321,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, strcpy(string, relabase); lslash= BLI_last_slash(string); - if(lslash) *(lslash+1)= 0; + if (lslash) *(lslash+1)= 0; dir+=2; /* Skip over the relative reference */ } @@ -1358,11 +1377,13 @@ int BLI_testextensie(const char *str, const char *ext) a= strlen(str); b= strlen(ext); - if(a==0 || b==0 || b>=a) { + if (a==0 || b==0 || b>=a) { retval = 0; - } else if (BLI_strcasecmp(ext, str + a - b)) { + } + else if (BLI_strcasecmp(ext, str + a - b)) { retval = 0; - } else { + } + else { retval = 1; } @@ -1372,8 +1393,8 @@ int BLI_testextensie(const char *str, const char *ext) int BLI_testextensie_array(const char *str, const char **ext_array) { int i=0; - while(ext_array[i]) { - if(BLI_testextensie(str, ext_array[i])) { + while (ext_array[i]) { + if (BLI_testextensie(str, ext_array[i])) { return 1; } @@ -1389,11 +1410,11 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) const char *ext_step= ext_fnmatch; char pattern[16]; - while(ext_step[0]) { + while (ext_step[0]) { char *ext_next; int len_ext; - if((ext_next=strchr(ext_step, ';'))) { + if ((ext_next=strchr(ext_step, ';'))) { len_ext= (int)(ext_next - ext_step) + 1; } else { @@ -1402,7 +1423,7 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) BLI_strncpy(pattern, ext_step, len_ext); - if(fnmatch(pattern, str, FNM_CASEFOLD)==0) { + if (fnmatch(pattern, str, FNM_CASEFOLD)==0) { return 1; } ext_step += len_ext; @@ -1418,7 +1439,7 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) size_t ext_len= strlen(ext); ssize_t a; - for(a= path_len - 1; a >= 0; a--) { + for (a= path_len - 1; a >= 0; a--) { if (ELEM3(path[a], '.', '/', '\\')) { break; } @@ -1428,7 +1449,7 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) a= path_len; } - if(a + ext_len >= maxlen) + if (a + ext_len >= maxlen) return 0; memcpy(path+a, ext, ext_len + 1); @@ -1449,7 +1470,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) return 1; } - for(a= path_len - 1; a >= 0; a--) { + for (a= path_len - 1; a >= 0; a--) { if (path[a] == '.') { path[a]= '\0'; } @@ -1459,7 +1480,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) } a++; - if(a + ext_len >= maxlen) + if (a + ext_len >= maxlen) return 0; memcpy(path+a, ext, ext_len + 1); @@ -1479,7 +1500,7 @@ void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t d if (dir) { if (lslash) { - BLI_strncpy( dir, string, MIN2(dirlen, lslash + 1)); /* +1 to include the slash and the last char */ + BLI_strncpy(dir, string, MIN2(dirlen, lslash + 1)); /* +1 to include the slash and the last char */ } else { dir[0] = '\0'; @@ -1507,7 +1528,7 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha size_t dirlen= BLI_strnlen(dir, maxlen); if (dst != dir) { - if(dirlen == maxlen) { + if (dirlen == maxlen) { memcpy(dst, dir, dirlen); dst[dirlen - 1]= '\0'; return; /* dir fills the path */ @@ -1522,9 +1543,9 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha } /* inline BLI_add_slash */ - if (dst[dirlen - 1] != SEP) { - dst[dirlen++]= SEP; - dst[dirlen ]= '\0'; + if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) { + dst[dirlen++] = SEP; + dst[dirlen ] = '\0'; } if (dirlen >= maxlen) { @@ -1671,7 +1692,7 @@ char *BLI_last_slash(const char *string) else return lfslash; } -/* adds a slash if there isnt one there already */ +/* adds a slash if there isn't one there already */ int BLI_add_slash(char *string) { int len = strlen(string); @@ -1691,7 +1712,8 @@ void BLI_del_slash(char *string) if (string[len-1] == SEP) { string[len-1] = '\0'; len--; - } else { + } + else { break; } } @@ -1718,7 +1740,8 @@ static int add_win32_extension(char *name) ext[temp - extensions] = 0; extensions = temp + 1; strcat(filename, ext); - } else { + } + else { strcat(filename, extensions); } @@ -1731,7 +1754,8 @@ static int add_win32_extension(char *name) } while (temp); } #endif - } else { + } + else { retval = 1; } @@ -1773,24 +1797,30 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name #endif #ifdef _WIN32 - if(GetModuleFileName(0, fullname, maxlen)) { - if(!BLI_exists(fullname)) { + wchar_t * fullname_16 = MEM_mallocN(maxlen*sizeof(wchar_t), "ProgramPath"); + if (GetModuleFileNameW(0, fullname_16, maxlen)) { + conv_utf_16_to_8(fullname_16,fullname, maxlen); + if (!BLI_exists(fullname)) { printf("path can't be found: \"%.*s\"\n", maxlen, fullname); MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } + MEM_freeN(fullname_16); return; } + + MEM_freeN(fullname_16); #endif /* unix and non linux */ if (name && name[0]) { + BLI_strncpy(fullname, name, maxlen); if (name[0] == '.') { char wdir[FILE_MAX]= ""; BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name - if(name[1]==SEP) + if (name[1]==SEP) BLI_join_dirfile(fullname, maxlen, wdir, name+2); else BLI_join_dirfile(fullname, maxlen, wdir, name); @@ -1801,7 +1831,8 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name // full path BLI_strncpy(fullname, name, maxlen); add_win32_extension(fullname); - } else { + } + else { // search for binary in $PATH path = getenv("PATH"); if (path) { @@ -1811,7 +1842,8 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name strncpy(filename, path, temp - path); filename[temp - path] = 0; path = temp + 1; - } else { + } + else { strncpy(filename, path, sizeof(filename)); } BLI_join_dirfile(fullname, maxlen, fullname, name); @@ -1891,11 +1923,12 @@ static void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir if (fullname[0] == '\0') { BLI_strncpy(fullname, "/tmp/", maxlen); - } else { + } + else { /* add a trailing slash if needed */ BLI_add_slash(fullname); #ifdef WIN32 - if(userdir && 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 |