summaryrefslogtreecommitdiff
path: root/src/util/String.c
diff options
context:
space:
mode:
authorallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-10-03 19:52:25 +0000
committerallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-10-03 19:52:25 +0000
commit7cbb6c19e27bb59daaec62b9a0a0eb74bb637450 (patch)
tree3a356c039af5f6c1f2f3287b04f7f60252cb9fa5 /src/util/String.c
parenta5c1edfb9c92c2a9cc33cf350874980188b2d197 (diff)
Added Util_SplitFilename which provides the directory and filename from a full name
git-svn-id: http://svn.cactuscode.org/flesh/trunk@1848 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util/String.c')
-rw-r--r--src/util/String.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/util/String.c b/src/util/String.c
index f101a8bf..3fc461c6 100644
--- a/src/util/String.c
+++ b/src/util/String.c
@@ -224,6 +224,52 @@ int Util_StrCmpi(const char *string1, const char *string2)
return retval;
}
+ /*@
+ @routine Util_SplitFilename
+ @date Wed Jan 20 10:14:00 1999
+ @author Tom Goodale
+ @desc
+ Splits a string into two parts at the given seperator.
+ Assigns memory for the two resulting strings, so this should be freed
+ when no longer needed.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int Util_SplitFilename(char **dir, char **file, const char *string)
+{
+ int retval=-1;
+ char *position;
+ char *copy;
+
+ copy = (char *)malloc(strlen(string)*sizeof(char));
+
+ strcpy(copy,string);
+
+ /* Find location of the seperator */
+ position = strrchr(copy, '/');
+
+ if(position)
+ {
+ retval = 0;
+ *file = position+1;
+ *dir = copy;
+ strcpy(position,"");
+ }
+ else
+ {
+ *file = copy;
+ *dir = NULL;
+ }
+
+ return retval;
+}
+
+
#ifdef TEST_Util_STRSEP