8498 ficl: variable 'count' might be clobbered by 'longjmp' or 'vfork'
[unleashed.git] / share / man / man3c / dirname.3c
blobc9e2c12b6472d066e29aec6e4d1ea5fa7892fdda
1 '\" te
2 .\"  Copyright 1989 AT&T  Copyright (c) 2002, Sun Microsystems, Inc.  All Rights Reserved  Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\"  This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH DIRNAME 3C "Mar 18, 2002"
11 .SH NAME
12 dirname \- report the parent directory name of a file path name
13 .SH SYNOPSIS
14 .LP
15 .nf
16 #include <libgen.h>
18 \fBchar *\fR\fBdirname\fR(\fBchar *\fR\fIpath\fR);
19 .fi
21 .SH DESCRIPTION
22 .sp
23 .LP
24 The \fBdirname()\fR function takes a pointer to a character string that
25 contains a pathname, and returns a pointer to a string that is a pathname of
26 the parent directory of that file.  Trailing '/' characters in the path are not
27 counted as part of the path.
28 .sp
29 .LP
30 If \fIpath\fR does not contain a '/', then \fBdirname()\fR returns a pointer to
31 the string "." .  If \fIpath\fR is a null pointer or points to an empty string,
32 \fBdirname()\fR returns a pointer to the string "." .
33 .SH RETURN VALUES
34 .sp
35 .LP
36 The \fBdirname()\fR function returns a pointer to a string that is the parent
37 directory of \fIpath\fR. If \fIpath\fR is a null pointer or points to an empty
38 string, a pointer to a string "." is returned.
39 .SH ERRORS
40 .sp
41 .LP
42 No errors are defined.
43 .SH EXAMPLES
44 .LP
45 \fBExample 1 \fRChanging the Current Directory to the Parent Directory.
46 .sp
47 .LP
48 The following code fragment reads a pathname, changes the current working
49 directory to the parent directory of the named file (see \fBchdir\fR(2)), and
50 opens the file.
52 .sp
53 .in +2
54 .nf
55 char path[[MAXPATHLEN], *pathcopy;
56 int fd;
57 fgets(path, MAXPATHLEN, stdin);
58 pathcopy = strdup(path);
59 chdir(dirname(pathcopy));
60 fd = open(basename(path), O_RDONLY);
61 .fi
62 .in -2
64 .LP
65 \fBExample 2 \fRSample Input and Output Strings for \fBdirname()\fR.
66 .sp
67 .LP
68 In the following table, the input string is the value pointed to by \fIpath\fR,
69 and the output string is the return value of the \fBdirname()\fR function.
71 .sp
73 .sp
74 .TS
75 box;
76 c | c
77 l | l .
78 \fBInput String\fR      \fBOutput String\fR
80 "/usr/lib""     "/usr"
82 "/usr/" "/"
84 "usr"   "/"
86 "/"     "/"
88 "."     "."
90 ".."    "."
91 .TE
93 .SH USAGE
94 .sp
95 .LP
96 The \fBdirname()\fR function modifies the string pointed to by \fIpath\fR.
97 .sp
98 .LP
99 The \fBdirname()\fR and \fBbasename\fR(3C) functions together yield a complete
100 pathname.  The expression \fBdirname(\fR\fIpath\fR\fB)\fR obtains the pathname
101 of the directory where \fBbasename(\fR\fIpath\fR\fB)\fR is found.
102 .SH ATTRIBUTES
105 See \fBattributes\fR(5) for descriptions of the following attributes:
110 box;
111 c | c
112 l | l .
113 ATTRIBUTE TYPE  ATTRIBUTE VALUE
115 Interface Stability     Standard
117 MT-Level        MT-Safe
120 .SH SEE ALSO
123 \fBbasename\fR(1), \fBchdir\fR(2), \fBbasename\fR(3C), \fBattributes\fR(5),
124 \fBstandards\fR(5)