[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58584] trunk/blender/source/blender: add api function BLI_path_append to add to a path (and ensure a seperator) , replaces BLI_join_dirfile when the dir and the destimation were the same.
Campbell Barton
ideasman42 at gmail.com
Wed Jul 24 23:25:07 CEST 2013
Revision: 58584
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58584
Author: campbellbarton
Date: 2013-07-24 21:25:06 +0000 (Wed, 24 Jul 2013)
Log Message:
-----------
add api function BLI_path_append to add to a path (and ensure a seperator), replaces BLI_join_dirfile when the dir and the destimation were the same.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_path_util.h
trunk/blender/source/blender/blenlib/intern/fileops.c
trunk/blender/source/blender/blenlib/intern/path_util.c
trunk/blender/source/blender/editors/interface/interface_ops.c
trunk/blender/source/blender/imbuf/intern/indexer.c
Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h 2013-07-24 20:53:24 UTC (rev 58583)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h 2013-07-24 21:25:06 UTC (rev 58584)
@@ -89,7 +89,18 @@
void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen);
void BLI_split_file_part(const char *string, char *file, const size_t filelen);
-void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file);
+void BLI_path_append(char *__restrict dst, const size_t maxlen,
+ const char *__restrict file)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+void BLI_join_dirfile(char *__restrict string, const size_t maxlen,
+ const char *__restrict dir, const char *__restrict file)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
const char *BLI_path_basename(const char *path);
typedef enum bli_rebase_state {
Modified: trunk/blender/source/blender/blenlib/intern/fileops.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/fileops.c 2013-07-24 20:53:24 UTC (rev 58583)
+++ trunk/blender/source/blender/blenlib/intern/fileops.c 2013-07-24 21:25:06 UTC (rev 58584)
@@ -445,7 +445,7 @@
size_t len = strlen(dir) + strlen(file) + 1;
if (*dst == NULL)
- *dst = MEM_callocN(len + 1, "join_dirfile_alloc path");
+ *dst = MEM_mallocN(len + 1, "join_dirfile_alloc path");
else if (*alloc_len < len)
*dst = MEM_reallocN(*dst, len + 1);
Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c 2013-07-24 20:53:24 UTC (rev 58583)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c 2013-07-24 21:25:06 UTC (rev 58584)
@@ -1691,6 +1691,26 @@
}
/**
+ * Append a filename to a dir, ensuring slash separates.
+ */
+void BLI_path_append(char *dst, const size_t maxlen, const char *file)
+{
+ size_t dirlen = BLI_strnlen(dst, maxlen);
+
+ /* inline BLI_add_slash */
+ if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) {
+ dst[dirlen++] = SEP;
+ dst[dirlen] = '\0';
+ }
+
+ if (dirlen >= maxlen) {
+ return; /* fills the path */
+ }
+
+ BLI_strncpy(dst + dirlen, file, maxlen - dirlen);
+}
+
+/**
* Simple appending of filename to dir, does not check for valid path!
* Puts result into *dst, which may be same area as *dir.
*/
@@ -1698,16 +1718,17 @@
{
size_t dirlen = BLI_strnlen(dir, maxlen);
- if (dst != dir) {
- if (dirlen == maxlen) {
- memcpy(dst, dir, dirlen);
- dst[dirlen - 1] = '\0';
- return; /* dir fills the path */
- }
- else {
- memcpy(dst, dir, dirlen + 1);
- }
+ /* args can't match */
+ BLI_assert(!ELEM(dst, dir, file));
+
+ if (dirlen == maxlen) {
+ memcpy(dst, dir, dirlen);
+ dst[dirlen - 1] = '\0';
+ return; /* dir fills the path */
}
+ else {
+ memcpy(dst, dir, dirlen + 1);
+ }
if (dirlen + 1 >= maxlen) {
return; /* fills the path */
@@ -1723,10 +1744,6 @@
return; /* fills the path */
}
- if (file == NULL) {
- return;
- }
-
BLI_strncpy(dst + dirlen, file, maxlen - dirlen);
}
@@ -1842,7 +1859,7 @@
/* subdirectories relative to blend_dir */
BLI_join_dirfile(dest_path, sizeof(dest_path), dest_dir, rel_dir);
/* same subdirectories relative to dest_dir */
- BLI_join_dirfile(dest_path, sizeof(dest_path), dest_path, base);
+ BLI_path_append(dest_path, sizeof(dest_path), base);
/* keeping original item basename */
}
@@ -2063,7 +2080,7 @@
else {
strncpy(filename, path, sizeof(filename));
}
- BLI_join_dirfile(fullname, maxlen, fullname, name);
+ BLI_path_append(fullname, maxlen, name);
if (add_win32_extension(filename)) {
BLI_strncpy(fullname, filename, maxlen);
break;
Modified: trunk/blender/source/blender/editors/interface/interface_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_ops.c 2013-07-24 20:53:24 UTC (rev 58583)
+++ trunk/blender/source/blender/editors/interface/interface_ops.c 2013-07-24 21:25:06 UTC (rev 58584)
@@ -917,7 +917,7 @@
/* First, full lang code. */
BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng);
BLI_join_dirfile(path, maxlen, root, uilng);
- BLI_join_dirfile(path, maxlen, path, tstr);
+ BLI_path_append(path, maxlen, tstr);
if (BLI_is_file(path))
return;
@@ -941,7 +941,7 @@
BLI_join_dirfile(path, maxlen, root, tstr);
strcat(tstr, ".po");
- BLI_join_dirfile(path, maxlen, path, tstr);
+ BLI_path_append(path, maxlen, tstr);
if (BLI_is_file(path))
return;
}
Modified: trunk/blender/source/blender/imbuf/intern/indexer.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/indexer.c 2013-07-24 20:53:24 UTC (rev 58583)
+++ trunk/blender/source/blender/imbuf/intern/indexer.c 2013-07-24 21:25:06 UTC (rev 58584)
@@ -366,8 +366,8 @@
if (!anim->index_dir[0]) {
char fname[FILE_MAXFILE];
BLI_split_dirfile(anim->name, index_dir, fname, index_dir_len, sizeof(fname));
- BLI_join_dirfile(index_dir, index_dir_len, index_dir, "BL_proxy");
- BLI_join_dirfile(index_dir, index_dir_len, index_dir, fname);
+ BLI_path_append(index_dir, index_dir_len, "BL_proxy");
+ BLI_path_append(index_dir, index_dir_len, fname);
}
else {
BLI_strncpy(index_dir, anim->index_dir, index_dir_len);
More information about the Bf-blender-cvs
mailing list