1basename(3C)             Standard C Library Functions             basename(3C)
2
3
4

NAME

6       basename - return the last element of a path name
7

SYNOPSIS

9       #include <libgen.h>
10
11       char *basename(char *path);
12
13

DESCRIPTION

15       The  basename()  function  takes  the  pathname  pointed to by path and
16       returns a pointer to the final component of the pathname, deleting  any
17       trailing '/' characters.
18
19
20       If  the  string  consists  entirely  of  the  '/' character, basename()
21       returns a pointer to the string "/" .
22
23
24       If path is a null pointer or points  to  an  empty  string,  basename()
25       returns a pointer to the string "." .
26

RETURN VALUES

28       The  basename()  function  returns  a pointer to the final component of
29       path.
30

USAGE

32       The basename() function may modify the string pointed to by  path,  and
33       may  return a pointer to static storage that may then be overwritten by
34       a subsequent call to basename().
35
36
37       When compiling multithreaded applications, the _REENTRANT flag must  be
38       defined  on  the compile line.  This flag should only be used in multi‐
39       threaded applications.
40

EXAMPLES

42       Example 1 Examples for Input String and Output String
43
44
45
46
47       ┌─────────────────────────────┬─────────────────────────────┐
48Input String          Output String         
49       ├─────────────────────────────┼─────────────────────────────┤
50       │"/usr/lib"                   │"lib"                        │
51       ├─────────────────────────────┼─────────────────────────────┤
52       │"/usr/"                      │"usr"                        │
53       ├─────────────────────────────┼─────────────────────────────┤
54       │"/"                          │"/"                          │
55       └─────────────────────────────┴─────────────────────────────┘
56

ATTRIBUTES

58       See attributes(5) for descriptions of the following attributes:
59
60
61
62
63       ┌─────────────────────────────┬─────────────────────────────┐
64       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
65       ├─────────────────────────────┼─────────────────────────────┤
66       │Interface Stability          │Standard                     │
67       ├─────────────────────────────┼─────────────────────────────┤
68       │MT-Level                     │MT-Safe                      │
69       └─────────────────────────────┴─────────────────────────────┘
70

SEE ALSO

72       basename(1), dirname(3C), attributes(5), standards(5)
73
74
75
76SunOS 5.11                        24 Jul 2002                     basename(3C)
Impressum