Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-01-26 18:58:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-01-26 18:59:24 +0300
commit7bc6fbf158556331e247b714f874b919b9af9ae7 (patch)
treec5b3c883d6a4243f2f11bbac9306abdee07e1207 /source/blender/blenlib
parentfca515838e70f8bec7028b840bb921a1be9fabbb (diff)
Cleanup: current/parent paths: add helpers in BLI_path_utils.
Also, avoid calling ugly strcmp with '.' or '..', making direct char checks is much cheaper here!
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_path_util.h9
-rw-r--r--source/blender/blenlib/intern/fileops.c4
-rw-r--r--source/blender/blenlib/intern/path_util.c4
-rw-r--r--source/blender/blenlib/intern/storage.c8
4 files changed, 17 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 8daaff1cea6..7103f8a7597 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -165,6 +165,15 @@ void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
# define FILE_MAX 1024
#endif
+/* Parent and current dir helpers. */
+#define FILENAME_PARENT ".."
+#define FILENAME_CURRENT "."
+
+/* Avoid calling strcmp on one or two chars! */
+#define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
+#define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
+#define FILENAME_IS_CURRPAR(_n) (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 8ae99c0da97..d6fe5e52b95 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -316,7 +316,7 @@ static bool delete_recursive(const char *dir)
while (i--) {
char file[8];
BLI_split_file_part(fl->path, file, sizeof(file));
- if (STREQ(file, ".") || STREQ(file, "..")) {
+ if (FILENAME_IS_CURRPAR(file)) {
/* Skip! */
}
else if (S_ISDIR(fl->type)) {
@@ -584,7 +584,7 @@ static int recursive_operation(const char *startfrom, const char *startto,
for (i = 0; i < n; i++) {
const struct dirent * const dirent = dirlist[i];
- if (STREQ(dirent->d_name, ".") || STREQ(dirent->d_name, ".."))
+ if (FILENAME_IS_CURRPAR(dirent->d_name))
continue;
join_dirfile_alloc(&from_path, &from_alloc_len, from, dirent->d_name);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 0cc7524bfb5..cc9fbc85a09 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1116,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) {
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 0d09b50a52c..38a15ab0a6d 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -135,10 +135,10 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2)
/* OK, now we know their S_IFMT fields are the same, go on to a name comparison */
/* make sure "." and ".." are always first */
- if (STREQ(entry1->relname, ".")) return (-1);
- if (STREQ(entry2->relname, ".")) return (1);
- if (STREQ(entry1->relname, "..")) return (-1);
- if (STREQ(entry2->relname, "..")) return (1);
+ if (FILENAME_IS_CURRENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_CURRENT(entry2->relname)) return (1);
+ if (FILENAME_IS_PARENT(entry1->relname)) return (-1);
+ if (FILENAME_IS_PARENT(entry2->relname)) return (1);
return (BLI_natstrcmp(entry1->relname, entry2->relname));
}