xref: /openbsd/lib/libc/gen/basename.3 (revision db3296cf)
1.\" $OpenBSD: basename.3,v 1.18 2003/07/30 22:29:32 millert Exp $
2.\"
3.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd August 17, 1997
18.Dt BASENAME 3
19.Os
20.Sh NAME
21.Nm basename
22.Nd extract the base portion of a pathname
23.Sh SYNOPSIS
24.Fd #include <libgen.h>
25.Ft char *
26.Fn basename "const char *path"
27.Sh DESCRIPTION
28The
29.Fn basename
30function returns the last component from the pathname pointed to by
31.Ar path ,
32deleting any trailing
33.Sq \&/
34characters.
35If
36.Ar path
37consists entirely of
38.Sq \&/
39characters, a pointer to the string
40.Qq \&/
41is returned.
42If
43.Ar path
44is a null pointer or the empty string, a pointer to the string
45.Qq \&.
46is returned.
47.Sh RETURN VALUES
48On successful completion,
49.Fn basename
50returns a pointer to the last component of
51.Ar path .
52.Pp
53If
54.Fn basename
55fails, a null pointer is returned and the global variable
56.Va errno
57is set to indicate the error.
58.Sh ERRORS
59The following error codes may be set in
60.Va errno :
61.Bl -tag -width Er
62.It Bq Er ENAMETOOLONG
63The path component to be returned was larger than
64.Dv MAXPATHLEN .
65.El
66.Sh WARNINGS
67.Fn basename
68returns a pointer to internal static storage space that will be overwritten
69by subsequent calls.
70.Sh SEE ALSO
71.Xr basename 1 ,
72.Xr dirname 1 ,
73.Xr dirname 3
74.Sh STANDARDS
75The
76.Fn basename
77function conforms to
78.St -xpg4.2 .
79.Sh HISTORY
80The
81.Fn basename
82function first appeared in
83.Ox 2.2 .
84.Sh AUTHORS
85.An Todd C. Miller
86