xref: /freebsd/lib/libc/stdlib/realpath.3 (revision d01a28e222cb4a0478324b12527a31cbfa4b8dfa)
1d01a28e2SPeter Wemm.\" Copyright (c) 1994
2d01a28e2SPeter Wemm.\"	The Regents of the University of California.  All rights reserved.
3d01a28e2SPeter Wemm.\"
4d01a28e2SPeter Wemm.\" This code is derived from software contributed to Berkeley by
5d01a28e2SPeter Wemm.\" Jan-Simon Pendry.
6d01a28e2SPeter Wemm.\"
7d01a28e2SPeter Wemm.\" Redistribution and use in source and binary forms, with or without
8d01a28e2SPeter Wemm.\" modification, are permitted provided that the following conditions
9d01a28e2SPeter Wemm.\" are met:
10d01a28e2SPeter Wemm.\" 1. Redistributions of source code must retain the above copyright
11d01a28e2SPeter Wemm.\"    notice, this list of conditions and the following disclaimer.
12d01a28e2SPeter Wemm.\" 2. Redistributions in binary form must reproduce the above copyright
13d01a28e2SPeter Wemm.\"    notice, this list of conditions and the following disclaimer in the
14d01a28e2SPeter Wemm.\"    documentation and/or other materials provided with the distribution.
15d01a28e2SPeter Wemm.\" 3. All advertising materials mentioning features or use of this software
16d01a28e2SPeter Wemm.\"    must display the following acknowledgement:
17d01a28e2SPeter Wemm.\"	This product includes software developed by the University of
18d01a28e2SPeter Wemm.\"	California, Berkeley and its contributors.
19d01a28e2SPeter Wemm.\" 4. Neither the name of the University nor the names of its contributors
20d01a28e2SPeter Wemm.\"    may be used to endorse or promote products derived from this software
21d01a28e2SPeter Wemm.\"    without specific prior written permission.
22d01a28e2SPeter Wemm.\"
23d01a28e2SPeter Wemm.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24d01a28e2SPeter Wemm.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25d01a28e2SPeter Wemm.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26d01a28e2SPeter Wemm.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27d01a28e2SPeter Wemm.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28d01a28e2SPeter Wemm.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29d01a28e2SPeter Wemm.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30d01a28e2SPeter Wemm.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31d01a28e2SPeter Wemm.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32d01a28e2SPeter Wemm.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33d01a28e2SPeter Wemm.\" SUCH DAMAGE.
34d01a28e2SPeter Wemm.\"
35d01a28e2SPeter Wemm.\"     @(#)realpath.3	8.2 (Berkeley) 2/16/94
36d01a28e2SPeter Wemm.\"
37d01a28e2SPeter Wemm.Dd "February 16, 1994"
38d01a28e2SPeter Wemm.Dt REALPATH 3
39d01a28e2SPeter Wemm.Os
40d01a28e2SPeter Wemm.Sh NAME
41d01a28e2SPeter Wemm.Nm realpath
42d01a28e2SPeter Wemm.Nd returns the canonicalized absolute pathname
43d01a28e2SPeter Wemm.Sh SYNOPSIS
44d01a28e2SPeter Wemm.Fd #include <sys/param.h>
45d01a28e2SPeter Wemm.Fd #include <stdlib.h>
46d01a28e2SPeter Wemm.Ft "char *"
47d01a28e2SPeter Wemm.Fn realpath "const char *pathname" "char resolvedname[MAXPATHLEN]"
48d01a28e2SPeter Wemm.Sh DESCRIPTION
49d01a28e2SPeter WemmThe
50d01a28e2SPeter Wemm.Fn realpath
51d01a28e2SPeter Wemmfunction resolves all symbolic links, extra
52d01a28e2SPeter Wemm.Dq /
53d01a28e2SPeter Wemmcharacters and references to
54d01a28e2SPeter Wemm.Pa /./
55d01a28e2SPeter Wemmand
56d01a28e2SPeter Wemm.Pa /../
57d01a28e2SPeter Wemmin
58d01a28e2SPeter Wemm.Fa pathname ,
59d01a28e2SPeter Wemmand copies the resulting absolute pathname into
60d01a28e2SPeter Wemmthe memory referenced by
61d01a28e2SPeter Wemm.Fa resolvedname .
62d01a28e2SPeter WemmThe
63d01a28e2SPeter Wemm.Fa resolvedname
64d01a28e2SPeter Wemmargument
65d01a28e2SPeter Wemm.Em must
66d01a28e2SPeter Wemmrefer to a buffer capable of storing at least
67d01a28e2SPeter Wemm.Dv MAXPATHLEN
68d01a28e2SPeter Wemmcharacters.
69d01a28e2SPeter Wemm.Pp
70d01a28e2SPeter WemmThe
71d01a28e2SPeter Wemm.Fn realpath
72d01a28e2SPeter Wemmfunction will resolve both absolute and relative paths
73d01a28e2SPeter Wemmand return the absolute pathname corresponding to
74d01a28e2SPeter Wemm.Fa pathname .
75d01a28e2SPeter WemmAll but the last component of
76d01a28e2SPeter Wemm.Fa pathname
77d01a28e2SPeter Wemmmust exist when
78d01a28e2SPeter Wemm.Fn realpath
79d01a28e2SPeter Wemmis called.
80d01a28e2SPeter Wemm.Sh "RETURN VALUES"
81d01a28e2SPeter WemmThe
82d01a28e2SPeter Wemm.Fn realpath
83d01a28e2SPeter Wemmfunction returns
84d01a28e2SPeter Wemm.Fa resolved_name
85d01a28e2SPeter Wemmon success.
86d01a28e2SPeter WemmIf an error occurs,
87d01a28e2SPeter Wemm.Fn realpath
88d01a28e2SPeter Wemmreturns
89d01a28e2SPeter Wemm.Dv NULL ,
90d01a28e2SPeter Wemmand
91d01a28e2SPeter Wemm.Fa resolved_name
92d01a28e2SPeter Wemmcontains the pathname which caused the problem.
93d01a28e2SPeter Wemm.Sh ERRORS
94d01a28e2SPeter WemmThe function
95d01a28e2SPeter Wemm.Fn realpath
96d01a28e2SPeter Wemmmay fail and set the external variable
97d01a28e2SPeter Wemm.Va errno
98d01a28e2SPeter Wemmfor any of the errors specified for the library functions
99d01a28e2SPeter Wemm.Xr chdir 2 ,
100d01a28e2SPeter Wemm.Xr close 2 ,
101d01a28e2SPeter Wemm.Xr fchdir 2 ,
102d01a28e2SPeter Wemm.Xr lstat 2 ,
103d01a28e2SPeter Wemm.Xr open 2 ,
104d01a28e2SPeter Wemm.Xr readlink 2
105d01a28e2SPeter Wemmand
106d01a28e2SPeter Wemm.Xr getcwd 3 .
107d01a28e2SPeter Wemm.Sh CAVEATS
108d01a28e2SPeter WemmThis implementation of
109d01a28e2SPeter Wemm.Fn realpath
110d01a28e2SPeter Wemmdiffers slightly from the Solaris implementation.
111d01a28e2SPeter WemmThe
112d01a28e2SPeter Wemm.Bx 4.4
113d01a28e2SPeter Wemmversion always returns absolute pathnames,
114d01a28e2SPeter Wemmwhereas the Solaris implementation will,
115d01a28e2SPeter Wemmunder certain circumstances, return a relative
116d01a28e2SPeter Wemm.Fa resolved_path
117d01a28e2SPeter Wemmwhen given a relative
118d01a28e2SPeter Wemm.Fa pathname .
119d01a28e2SPeter Wemm.Sh "SEE ALSO"
120d01a28e2SPeter Wemm.Xr getcwd 3
121d01a28e2SPeter Wemm.Sh HISTORY
122d01a28e2SPeter WemmThe
123d01a28e2SPeter Wemm.Fn realpath
124d01a28e2SPeter Wemmfunction call first appeared in
125d01a28e2SPeter Wemm.Bx 4.4 .
126