mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 20:10:18 +03:00
Added dirname()
This commit is contained in:
@@ -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 ".";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user