mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-24 12:11:33 +00:00
Added dirname()
This commit is contained in:
parent
816c8f3b89
commit
182e3ed61d
@ -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 ".";
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user