1 .\" $OpenBSD: basename.3,v 1.20 2007/05/31 19:19:28 jmc Exp $
3 .\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
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.
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.
24 .Nd extract the base portion of a pathname
28 .Fn basename "char *path"
30 .Fn basename_r "const char *path" "char *bname"
34 function returns the last component from the pathname pointed to by
43 characters, a pointer to the string
48 is a null pointer or the empty string, a pointer to the string
54 variation accepts a buffer of at least
56 bytes in which to store the resulting component.
57 .Sh IMPLEMENTATION NOTES
61 returns a pointer to internal storage space allocated on the first call
62 that will be overwritten
65 is therefore preferred for threaded applications.
67 On successful completion,
71 return pointers to the last component of
74 If they fail, a null pointer is returned and the global variable
76 is set to indicate the error.
78 The following error codes may be set in
81 .It Bq Er ENAMETOOLONG
82 The path component to be returned was larger than
97 function first appeared in
103 function first appeared in OS X 10.12.
108 returns a pointer to internal static storage space that will be overwritten
111 Other vendor implementations of
113 may modify the contents of the string passed to
115 this should be taken into account when writing code which calls this function
116 if portability is desired.