mirror of https://github.com/ipxe/ipxe.git
Added dirname()
parent
816c8f3b89
commit
182e3ed61d
|
@ -38,3 +38,25 @@ char * basename ( char *path ) {
|
||||||
basename = strrchr ( path, '/' );
|
basename = strrchr ( path, '/' );
|
||||||
return ( basename ? ( basename + 1 ) : 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
|
#ifndef _LIBGEN_H
|
||||||
#define _LIBGEN_H
|
#define _LIBGEN_H
|
||||||
|
|
||||||
char * basename ( char *path );
|
extern char * basename ( char *path );
|
||||||
|
extern char * dirname ( char *path );
|
||||||
|
|
||||||
#endif /* _LIBGEN_H */
|
#endif /* _LIBGEN_H */
|
||||||
|
|
Loading…
Reference in New Issue