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:
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 8adede3337c..ab7d082c432 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1430,21 +1430,40 @@ void BLI_split_dirfile(const char *string, char *dir, char *file)
}
/* simple appending of filename to dir, does not check for valid path! */
-void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file)
+void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const char *file)
{
- int sl_dir;
-
- if(string != dir) /* compare pointers */
- BLI_strncpy(string, dir, maxlen);
+ 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);
+ }
+ }
+
+ if (dirlen + 1 >= maxlen) {
+ return; /* fills the path */
+ }
+
+ /* inline BLI_add_slash */
+ if (dst[dirlen - 1] != SEP) {
+ dst[dirlen++]= SEP;
+ dst[dirlen ]= '\0';
+ }
+
+ if (dirlen >= maxlen) {
+ return; /* fills the path */
+ }
- if (!file)
+ if (file == NULL) {
return;
-
- sl_dir= BLI_add_slash(string);
-
- if (sl_dir <FILE_MAX) {
- BLI_strncpy(string + sl_dir, file, maxlen - sl_dir);
}
+
+ BLI_strncpy(dst + dirlen, file, maxlen - dirlen);
}
/* like pythons os.path.basename( ) */
@@ -1584,19 +1603,11 @@ char *BLI_last_slash(const char *string)
int BLI_add_slash(char *string)
{
int len = strlen(string);
-#ifdef WIN32
- if (len==0 || string[len-1]!='\\') {
- string[len] = '\\';
- string[len+1] = '\0';
- return len+1;
- }
-#else
- if (len==0 || string[len-1]!='/') {
- string[len] = '/';
+ if (len==0 || string[len-1] != SEP) {
+ string[len] = SEP;
string[len+1] = '\0';
return len+1;
}
-#endif
return len;
}
@@ -1605,11 +1616,7 @@ void BLI_del_slash(char *string)
{
int len = strlen(string);
while (len) {
-#ifdef WIN32
- if (string[len-1]=='\\') {
-#else
- if (string[len-1]=='/') {
-#endif
+ if (string[len-1] == SEP) {
string[len-1] = '\0';
len--;
} else {