iPXE
basename.c File Reference

Get base name of path. More...

#include <string.h>
#include <libgen.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
char * basename (char *path)
 Return base name from path.
char * dirname (char *path)
 Return directory name from path.

Detailed Description

Get base name of path.

Definition in file basename.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ basename()

char * basename ( char * path)

Return base name from path.

Parameters
pathFull path
Return values
basenameBase name

Definition at line 43 of file basename.c.

43 {
44 char *basename;
45
46 basename = strrchr ( path, '/' );
47 return ( basename ? ( basename + 1 ) : path );
48}
char * basename(char *path)
Return base name from path.
Definition basename.c:43
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition string.c:290

References basename(), and strrchr().

Referenced by basename(), image_set_uri(), and nfs_uri_init().

◆ dirname()

char * dirname ( char * path)

Return directory name from path.

Parameters
pathFull path
Return values
dirnameDirectory name

Note that this function may modify its argument.

Definition at line 58 of file basename.c.

58 {
59 char *separator;
60
61 separator = strrchr ( path, '/' );
62 if ( separator == path ) {
63 return "/";
64 } else if ( separator ) {
65 *separator = 0;
66 return path;
67 } else {
68 return ".";
69 }
70}

References strrchr().

Referenced by nfs_uri_init(), and resolve_path().