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