diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-29 14:32:38 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-29 14:32:38 +0400 |
commit | 635db3b3066b71d4c9c0f4a67d20aeff0d4b3810 (patch) | |
tree | 8ff6739fe6fadda6ed96141c024575f13e4ccf3d /source/blender/blenlib | |
parent | 1d9eaad73ae1ce8ddfbef68ffbf8c56ac06ac0ce (diff) |
code cleanup: add utility function BLI_path_is_rel()
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 15 |
3 files changed, 19 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9b68406cc54..35d7b8d9444 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -154,6 +154,8 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits); int BLI_path_cwd(char *path); void BLI_path_rel(char *file, const char *relfile); +int BLI_path_is_rel(const char *path); + #ifdef WIN32 # define BLI_path_cmp BLI_strcasecmp # define BLI_path_ncmp BLI_strncasecmp diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 6d95b078340..2a750cb1a66 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -113,13 +113,13 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) == 0) { + if (BLI_path_is_rel(path_src)) { return FALSE; /* already relative */ } else { strcpy(path_dst, path_src); BLI_path_rel(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) == 0) { + if (BLI_path_is_rel(path_dst)) { data->count_changed++; } else { @@ -155,13 +155,13 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char data->count_tot++; - if (strncmp(path_src, "//", 2) != 0) { + if (BLI_path_is_rel(path_src) == FALSE) { return FALSE; /* already absolute */ } else { strcpy(path_dst, path_src); BLI_path_abs(path_dst, data->basedir); - if (strncmp(path_dst, "//", 2) != 0) { + if (BLI_path_is_rel(path_dst) == FALSE) { data->count_changed++; } else { @@ -596,7 +596,7 @@ int BLI_bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *pat const char *base_new = ((char **)pathbase_v)[0]; const char *base_old = ((char **)pathbase_v)[1]; - if (strncmp(base_old, "//", 2) == 0) { + if (BLI_path_is_rel(base_old)) { printf("%s: error, old base path '%s' is not absolute.\n", __func__, base_old); return FALSE; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 22b160ad0b4..e6ecdeae2e9 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -411,6 +411,11 @@ void BLI_cleanup_file(const char *relabase, char *dir) BLI_del_slash(dir); } +int BLI_path_is_rel(const char *path) +{ + return path[0] == '/' && path[1] == '/'; +} + void BLI_path_rel(char *file, const char *relfile) { char *lslash; @@ -418,10 +423,14 @@ 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 (BLI_path_is_rel(file)) { + return; + } /* also bail out if relative path is not set */ - if (relfile[0] == 0) return; + if (relfile[0] == '\0') { + return; + } #ifdef WIN32 if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') { @@ -630,7 +639,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) int BLI_path_abs(char *path, const char *basepath) { - int wasrelative = (strncmp(path, "//", 2) == 0); + int wasrelative = BLI_path_is_rel(path); char tmp[FILE_MAX]; char base[FILE_MAX]; #ifdef WIN32 |