From 182e3ed61d8db574c2bf7a091ce2221746259cbd Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 3 Jun 2007 01:51:10 +0000 Subject: Added dirname() --- src/core/basename.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/core') 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 "."; + } +} -- cgit v1.2.3-55-g7522