Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/path_util.c
| Show First 20 Lines • Show All 1,067 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| bool retval = false; | bool retval = false; | ||||
| int type; | int type; | ||||
| type = BLI_exists(name); | type = BLI_exists(name); | ||||
| if ((type == 0) || S_ISDIR(type)) { | if ((type == 0) || S_ISDIR(type)) { | ||||
| /* typically 3-5, ".EXE", ".BAT"... etc */ | /* typically 3-5, ".EXE", ".BAT"... etc */ | ||||
| const int ext_max = 12; | const int ext_max = 12; | ||||
| const char *ext = getenv("PATHEXT"); | const char *ext = BLI_getenv("PATHEXT"); | ||||
| if (ext) { | if (ext) { | ||||
| const int name_len = strlen(name); | const int name_len = strlen(name); | ||||
| char *filename = alloca(name_len + ext_max); | char *filename = alloca(name_len + ext_max); | ||||
| char *filename_ext; | char *filename_ext; | ||||
| const char *ext_next; | const char *ext_next; | ||||
| /* null terminated in the loop */ | /* null terminated in the loop */ | ||||
| memcpy(filename, name, name_len); | memcpy(filename, name, name_len); | ||||
| Show All 37 Lines | bool BLI_path_program_search( | ||||
| bool retval = false; | bool retval = false; | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| const char separator = ';'; | const char separator = ';'; | ||||
| #else | #else | ||||
| const char separator = ':'; | const char separator = ':'; | ||||
| #endif | #endif | ||||
| path = getenv("PATH"); | path = BLI_getenv("PATH"); | ||||
| if (path) { | if (path) { | ||||
| char filename[FILE_MAX]; | char filename[FILE_MAX]; | ||||
| const char *temp; | const char *temp; | ||||
| do { | do { | ||||
| temp = strchr(path, separator); | temp = strchr(path, separator); | ||||
| if (temp) { | if (temp) { | ||||
| strncpy(filename, path, temp - path); | strncpy(filename, path, temp - path); | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Only set an env var if already not there. | * Only set an env var if already not there. | ||||
| * Like Unix setenv(env, val, 0); | * Like Unix setenv(env, val, 0); | ||||
| * | * | ||||
| * (not used anywhere). | * (not used anywhere). | ||||
| */ | */ | ||||
| void BLI_setenv_if_new(const char *env, const char *val) | void BLI_setenv_if_new(const char *env, const char *val) | ||||
| { | { | ||||
| if (getenv(env) == NULL) | if (BLI_getenv(env) == NULL) | ||||
| BLI_setenv(env, val); | BLI_setenv(env, val); | ||||
| } | } | ||||
| /** | /** | ||||
| * get an env var, result has to be used immediately | |||||
| */ | |||||
| const char* BLI_getenv(const char *env) | |||||
| { | |||||
campbellbarton: Comment seems wrong? | |||||
| #ifdef WIN32A | |||||
| static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/ | |||||
| if (GetEnvironmentVariableA(env, buffer, sizeof(buffer))) | |||||
| return buffer; | |||||
| else | |||||
| return NULL; | |||||
| #else | |||||
| # undef getenv | |||||
| return getenv(env); | |||||
| # define getenv getenv_poisioned | |||||
| #endif | |||||
| } | |||||
| /** | |||||
| * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of | * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of | ||||
| * the lowest-level directory that does exist and we can read. | * the lowest-level directory that does exist and we can read. | ||||
| */ | */ | ||||
| void BLI_make_exist(char *dir) | void BLI_make_exist(char *dir) | ||||
| { | { | ||||
| bool valid_path = true; | bool valid_path = true; | ||||
| /* Loop as long as cur path is not a dir, and we can get a parent path. */ | /* Loop as long as cur path is not a dir, and we can get a parent path. */ | ||||
| ▲ Show 20 Lines • Show All 737 Lines • Show Last 20 Lines | |||||
Comment seems wrong?