diff options
author | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2001-12-03 16:23:36 +0000 |
---|---|---|
committer | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2001-12-03 16:23:36 +0000 |
commit | d18a8419c95c15d7cde900920f9209638f780320 (patch) | |
tree | 354aa2d3d53af632eb39a671cc1f7f900a775cd9 | |
parent | 6b112e7c0d44cc89949c13a2c60f8dd83a14758e (diff) |
Fixed Util_SplitFilename() to allocate both the dir and basename string.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@2474 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | src/util/String.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/util/String.c b/src/util/String.c index 019e0505..c4031028 100644 --- a/src/util/String.c +++ b/src/util/String.c @@ -375,30 +375,30 @@ int Util_StrCmpi(const char *string1, const char *string2) -1 - out of memory @endreturndesc @@*/ -int Util_SplitFilename(char **dir, char **file, const char *string) +int Util_SplitFilename (char **dir, char **file, const char *string) { - int retval=-1; - char *position=NULL; - char *copy; + char *position; - copy = Util_Strdup(string); - /* Find location of the seperator */ - position = strrchr(copy, '/'); - if(position) - { - retval = 0; - *file = position+1; - *dir = copy; - strcpy(position,""); - } - else + *file = Util_Strdup (string); + + if (*file) { - *file = copy; - *dir = NULL; + /* Find location of the seperator */ + position = strrchr (*file, '/'); + if (position) + { + *dir = *file; + *position = 0; + *file = Util_Strdup (position + 1); + } + else + { + *dir = NULL; + } } - return retval; + return (*file ? 0 : -1); } /*@@ |