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