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