xref: /freebsd/lib/libc/gen/basename.3 (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1.\" $OpenBSD: basename.3,v 1.20 2007/05/31 19:19:28 jmc 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 May 22, 2017
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.In libgen.h
25.Ft char *
26.Fn basename "char *path"
27.Sh DESCRIPTION
28The
29.Fn basename
30function returns the last component from the pathname pointed to by
31.Fa path ,
32deleting any trailing
33.Sq \&/
34characters.
35.Sh IMPLEMENTATION NOTES
36This implementation of
37.Fn basename
38uses the buffer provided by the caller to store the resulting pathname
39component.
40Other vendor implementations may return a pointer to internal storage
41space instead.
42The advantage of the former approach is that it ensures thread-safety,
43while also placing no upper limit on the supported length of the
44pathname.
45.Sh RETURN VALUES
46If
47.Fa path
48consists entirely of
49.Sq \&/
50characters, a pointer to the string
51.Qq \&/
52is returned.
53If
54.Fa path
55is a null pointer or the empty string, a pointer to the string
56.Qq \&.
57is returned.
58Otherwise,
59it returns a pointer to the last component of
60.Fa path .
61.Sh SEE ALSO
62.Xr basename 1 ,
63.Xr dirname 1 ,
64.Xr dirname 3
65.Sh STANDARDS
66The
67.Fn basename
68function conforms to
69.St -xpg4.2 .
70.Sh HISTORY
71The
72.Fn basename
73function first appeared in
74.Ox 2.2
75and
76.Fx 4.2 .
77.Pp
78In
79.Fx 12.0 ,
80this function was reimplemented to store its result in the provided
81input buffer.
82There is no longer any need to use the
83.Fn basename_r
84function.
85.Sh AUTHORS
86.An Nuxi, the Netherlands
87