]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/dirname.3
Libc-1439.100.3.tar.gz
[apple/libc.git] / gen / FreeBSD / dirname.3
CommitLineData
1f2f436a 1.\" $OpenBSD: dirname.3,v 1.17 2007/05/31 19:19:28 jmc Exp $
5b2abdfb
A
2.\"
3.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
5b2abdfb 4.\"
1f2f436a
A
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.
5b2abdfb 8.\"
1f2f436a
A
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.
5b2abdfb 16.\"
1f2f436a 17.\" $FreeBSD: src/lib/libc/gen/dirname.3,v 1.10 2008/11/03 05:19:45 delphij Exp $
5b2abdfb 18.\"
1f2f436a 19.Dd October 12, 2006
5b2abdfb
A
20.Dt DIRNAME 3
21.Os
22.Sh NAME
23.Nm dirname
9385eb3d 24.Nd extract the directory part of a pathname
5b2abdfb
A
25.Sh SYNOPSIS
26.In libgen.h
27.Ft char *
ad3c9f2a
A
28.Fo dirname
29.Fa "char *path"
30.Fc
974e3884
A
31.Ft char *
32.Fo dirname_r
33.Fa "const char *path" "char *dname"
34.Fc
5b2abdfb
A
35.Sh DESCRIPTION
36The
37.Fn dirname
1f2f436a 38function is the converse of
5b2abdfb
A
39.Xr basename 3 ;
40it returns a pointer to the parent directory of the pathname pointed to by
9385eb3d 41.Fa path .
5b2abdfb
A
42Any trailing
43.Sq \&/
44characters are not counted as part of the directory
45name.
46If
9385eb3d 47.Fa path
5b2abdfb
A
48is a null pointer, the empty string, or contains no
49.Sq \&/
50characters,
51.Fn dirname
52returns a pointer to the string
53.Qq \&. ,
54signifying the current directory.
1f2f436a
A
55.Sh IMPLEMENTATION NOTES
56The
57.Fn dirname
58function
59returns a pointer to internal storage space allocated on the first call
60that will be overwritten
61by subsequent calls.
974e3884
A
62.Fn dirname_r
63is therefore preferred for threaded applications.
1f2f436a
A
64.Pp
65Other vendor implementations of
66.Fn dirname
67may modify the contents of the string passed to
68.Fn dirname ;
ad3c9f2a
A
69if portability is desired,
70this should be taken into account when writing code which calls this function.
71.Sh LEGACY SYNOPSIS
72.Fd #include <libgen.h>
73.Pp
74.Ft char *
75.br
76.Fo dirname
77.Fa "const char *path"
78.Fc ;
79.Pp
80In legacy mode,
81.Fa path
82will not be changed.
5b2abdfb
A
83.Sh RETURN VALUES
84On successful completion,
85.Fn dirname
86returns a pointer to the parent directory of
9385eb3d 87.Fa path .
5b2abdfb
A
88.Pp
89If
90.Fn dirname
91fails, a null pointer is returned and the global variable
92.Va errno
93is set to indicate the error.
94.Sh ERRORS
95The following error codes may be set in
96.Va errno :
97.Bl -tag -width Er
98.It Bq Er ENAMETOOLONG
99The path component to be returned was larger than
100.Dv MAXPATHLEN .
974e3884
A
101.It Bq Er ENOMEM
102The static buffer used for storing the path in
103.Fn dirname
104could not be allocated.
5b2abdfb 105.El
5b2abdfb
A
106.Sh SEE ALSO
107.Xr basename 1 ,
108.Xr dirname 1 ,
ad3c9f2a
A
109.Xr basename 3 ,
110.Xr compat 5
5b2abdfb
A
111.Sh STANDARDS
112The
113.Fn dirname
114function conforms to
115.St -xpg4.2 .
116.Sh HISTORY
117The
118.Fn dirname
119function first appeared in
120.Ox 2.2
121and
122.Fx 4.2 .
974e3884
A
123The
124.Fn dirname_r
125function first appeared in OS X 10.12.
5b2abdfb 126.Sh AUTHORS
1f2f436a 127.An "Todd C. Miller"