summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/basename.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/basename.c b/src/core/basename.c
index f50b71513..7340c0d55 100644
--- a/src/core/basename.c
+++ b/src/core/basename.c
@@ -38,3 +38,25 @@ char * basename ( char *path ) {
basename = strrchr ( path, '/' );
return ( basename ? ( basename + 1 ) : path );
}
+
+/**
+ * Return directory name from path
+ *
+ * @v path Full path
+ * @ret dirname Directory name
+ *
+ * Note that this function may modify its argument.
+ */
+char * dirname ( char *path ) {
+ char *separator;
+
+ separator = strrchr ( path, '/' );
+ if ( separator == path ) {
+ return "/";
+ } else if ( separator ) {
+ *separator = 0;
+ return path;
+ } else {
+ return ".";
+ }
+}