diff options
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 3fff22218e2..fb4c31d5cdf 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -346,7 +346,7 @@ void BLI_cleanup_path(const char *relabase, char *path) /* Note * memmove(start, eind, strlen(eind) + 1); * is the same as - * strcpy( start, eind ); + * strcpy(start, eind); * except strcpy should not be used because there is overlap, * so use memmove's slightly more obscure syntax - Campbell */ @@ -428,6 +428,23 @@ void BLI_cleanup_file(const char *relabase, char *path) BLI_del_slash(path); } + +/** + * Make given name safe to be used in paths. + * + * For now, simply replaces reserved chars (as listed in + * http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words ) + * by underscores ('_'). + */ +void BLI_filename_make_safe(char *fname) +{ + const char *invalid = "/\\?%*:|\"<>. "; + + for (; *fname && (fname = strpbrk(fname, invalid)); fname++) { + *fname = '_'; + } +} + /** * Does path begin with the special "//" prefix that Blender uses to indicate * a path relative to the .blend file. @@ -1099,9 +1116,9 @@ void BLI_make_exist(char *dir) a = strlen(dir); - for (BLI_join_dirfile(par_path, sizeof(par_path), dir, ".."); + for (BLI_join_dirfile(par_path, sizeof(par_path), dir, FILENAME_PARENT); !(BLI_is_dir(dir) && BLI_exists(par_path)); - BLI_join_dirfile(par_path, sizeof(par_path), dir, "..")) + BLI_join_dirfile(par_path, sizeof(par_path), dir, FILENAME_PARENT)) { a--; while (dir[a] != SEP) { @@ -1352,9 +1369,7 @@ bool BLI_ensure_extension(char *path, size_t maxlen, const char *ext) ssize_t a; /* first check the extension is already there */ - if ( (ext_len <= path_len) && - (strcmp(path + (path_len - ext_len), ext) == 0)) - { + if ((ext_len <= path_len) && (STREQ(path + (path_len - ext_len), ext))) { return true; } |