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