xref: /freebsd/lib/libc/gen/dirname.3 (revision 06fd1dab305c3e522c8dcc785fe206c0ca995b77)
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 July 29, 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.
40If
41.Fa path
42is a null pointer, the empty string, or contains no
43.Sq \&/
44characters,
45.Fn dirname
46returns a pointer to the string
47.Qq \&. ,
48signifying the current directory.
49.Sh IMPLEMENTATION NOTES
50The
51.Fn dirname
52function
53returns a pointer to internal storage space allocated on the first call
54that will be overwritten
55by subsequent calls.
56.Pp
57Other vendor implementations of
58.Fn dirname
59may store their result in the input buffer,
60making it safe to use in multithreaded applications.
61Future versions of
62.Fx
63will follow this approach as well.
64.Sh RETURN VALUES
65On successful completion,
66.Fn dirname
67returns a pointer to the parent directory of
68.Fa path .
69.Pp
70If
71.Fn dirname
72fails, a null pointer is returned and the global variable
73.Va errno
74is set to indicate the error.
75.Sh ERRORS
76The following error codes may be set in
77.Va errno :
78.Bl -tag -width Er
79.It Bq Er ENAMETOOLONG
80The path component to be returned was larger than
81.Dv MAXPATHLEN .
82.El
83.Sh SEE ALSO
84.Xr basename 1 ,
85.Xr dirname 1 ,
86.Xr basename 3
87.Sh STANDARDS
88The
89.Fn dirname
90function conforms to
91.St -xpg4.2 .
92.Sh HISTORY
93The
94.Fn dirname
95function first appeared in
96.Ox 2.2
97and
98.Fx 4.2 .
99.Sh AUTHORS
100.An "Todd C. Miller"
101