2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-12-24 12:11:33 +00:00

Added dirname()

This commit is contained in:
Michael Brown 2007-06-03 01:51:10 +00:00
parent 816c8f3b89
commit 182e3ed61d
2 changed files with 24 additions and 1 deletions

View File

@ -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 ".";
}
}

View File

@ -1,6 +1,7 @@
#ifndef _LIBGEN_H
#define _LIBGEN_H
char * basename ( char *path );
extern char * basename ( char *path );
extern char * dirname ( char *path );
#endif /* _LIBGEN_H */