1BASENAME(P)                POSIX Programmer's Manual               BASENAME(P)
2
3
4

NAME

6       basename - return the last component of a pathname
7

SYNOPSIS

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

DESCRIPTION

15       The  basename() function shall take the pathname pointed to by path and
16       return a pointer to the final component of the pathname,  deleting  any
17       trailing '/' characters.
18
19       If  the string consists entirely of the '/' character, basename() shall
20       return a pointer to the string "/" . If the string is exactly "//" , it
21       is implementation-defined whether '/' or "//" is returned.
22
23       If  path  is  a  null  pointer or points to an empty string, basename()
24       shall return a pointer to the string "." .
25
26       The basename() function may modify the string pointed to by  path,  and
27       may  return a pointer to static storage that may then be overwritten by
28       a subsequent call to basename().
29
30       The basename() function need not be reentrant. A function that  is  not
31       required to be reentrant is not required to be thread-safe.
32

RETURN VALUE

34       The  basename()  function shall return a pointer to the final component
35       of path.
36

ERRORS

38       No errors are defined.
39
40       The following sections are informative.
41

EXAMPLES

43   Using basename()
44       The following program fragment returns a  pointer  to  the  value  lib,
45       which is the base name of /usr/lib.
46
47
48              #include <libgen.h>
49              ...
50              char *name = "/usr/lib";
51              char *base;
52
53
54              base = basename(name);
55              ...
56
57   Sample Input and Output Strings for basename()
58       In  the  following  table,  the input string is the value pointed to by
59       path, and the output string is the return value of the basename() func‐
60       tion.
61
62                           Input String     Output String
63                           "/usr/lib"       "lib"
64                           "/usr/"          "usr"
65                           "/"              "/"
66
67                           "///"            "/"
68                           "//usr//lib//"   "lib"
69

APPLICATION USAGE

71       None.
72

RATIONALE

74       None.
75

FUTURE DIRECTIONS

77       None.
78

SEE ALSO

80       dirname()  , the Base Definitions volume of IEEE Std 1003.1-2001, <lib‐
81       gen.h>, the Shell and Utilities volume of  IEEE Std 1003.1-2001,  base‐
82       name
83
85       Portions  of  this text are reprinted and reproduced in electronic form
86       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
87       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
88       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
89       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
90       event of any discrepancy between this version and the original IEEE and
91       The  Open Group Standard, the original IEEE and The Open Group Standard
92       is the referee document. The original Standard can be  obtained  online
93       at http://www.opengroup.org/unix/online.html .
94
95
96
97IEEE/The Open Group                  2003                          BASENAME(P)
Impressum