|
@@ -38,3 +38,25 @@ char * basename ( char *path ) {
|
38
|
38
|
basename = strrchr ( path, '/' );
|
39
|
39
|
return ( basename ? ( basename + 1 ) : path );
|
40
|
40
|
}
|
|
41
|
+
|
|
42
|
+/**
|
|
43
|
+ * Return directory name from path
|
|
44
|
+ *
|
|
45
|
+ * @v path Full path
|
|
46
|
+ * @ret dirname Directory name
|
|
47
|
+ *
|
|
48
|
+ * Note that this function may modify its argument.
|
|
49
|
+ */
|
|
50
|
+char * dirname ( char *path ) {
|
|
51
|
+ char *separator;
|
|
52
|
+
|
|
53
|
+ separator = strrchr ( path, '/' );
|
|
54
|
+ if ( separator == path ) {
|
|
55
|
+ return "/";
|
|
56
|
+ } else if ( separator ) {
|
|
57
|
+ *separator = 0;
|
|
58
|
+ return path;
|
|
59
|
+ } else {
|
|
60
|
+ return ".";
|
|
61
|
+ }
|
|
62
|
+}
|