1.\" $OpenBSD: dirname.3,v 1.17 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 August 12, 2016 20.Dt DIRNAME 3 21.Os 22.Sh NAME 23.Nm dirname 24.Nd extract the directory part of a pathname 25.Sh SYNOPSIS 26.In libgen.h 27.Ft char * 28.Fn dirname "char *path" 29.Sh DESCRIPTION 30The 31.Fn dirname 32function is the converse of 33.Xr basename 3 ; 34it returns a pointer to the parent directory of the pathname pointed to by 35.Fa path . 36Any trailing 37.Sq \&/ 38characters are not counted as part of the directory 39name. 40.Sh RETURN VALUES 41If 42.Fa path 43is a null pointer, the empty string, or contains no 44.Sq \&/ 45characters, 46.Fn dirname 47returns a pointer to the string 48.Qq \&. , 49signifying the current directory. 50Otherwise, 51it returns a pointer to the parent directory of 52.Fa path . 53.Sh IMPLEMENTATION NOTES 54This implementation of 55.Fn dirname 56uses the buffer provided by the caller to store the resulting parent 57directory. 58Other vendor implementations may return a pointer to internal storage 59space instead. 60The advantage of the former approach is that it ensures thread-safety, 61while also placing no upper limit on the supported length of the 62pathname. 63.Pp 64The algorithm used by this implementation also discards redundant 65slashes and 66.Qq \&. 67pathname components from the pathname string. 68.Sh SEE ALSO 69.Xr basename 1 , 70.Xr dirname 1 , 71.Xr basename 3 72.Sh STANDARDS 73The 74.Fn dirname 75function conforms to 76.St -xpg4.2 . 77.Sh HISTORY 78The 79.Fn dirname 80function first appeared in 81.Ox 2.2 82and 83.Fx 4.2 . 84.Pp 85In 86.Fx 12.0 , 87this function was reimplemented to store its result in the provided 88input buffer. 89.Sh AUTHORS 90.An Nuxi, the Netherlands 91