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