xref: /netbsd-src/lib/libc/gen/realpath.3 (revision a4ddc2c8fb9af816efe3b1c375a5530aef0e89e9)
1.\"	$NetBSD: realpath.3,v 1.16 2013/03/05 03:11:27 enami 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. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     from: @(#)realpath.3	8.2 (Berkeley) 2/16/94
34.\"
35.Dd June 21, 2012
36.Dt REALPATH 3
37.Os
38.Sh NAME
39.Nm realpath
40.Nd returns the canonicalized absolute pathname
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In sys/param.h
45.In stdlib.h
46.Ft "char *"
47.Fn realpath "const char * restrict pathname" "char * restrict resolvedname"
48.Sh DESCRIPTION
49The
50.Fn realpath
51function resolves all symbolic links, extra
52.Dq /
53characters and references to
54.Pa /./
55and
56.Pa /../
57in
58.Fa pathname ,
59and copies the resulting absolute pathname into
60the memory referenced by
61.Fa resolvedname .
62The
63.Fa resolvedname
64argument
65.Em must
66refer to a buffer capable of storing at least
67.Dv MAXPATHLEN
68characters, or be
69.Dv NULL .
70.Pp
71The
72.Fn realpath
73function will resolve both absolute and relative paths
74and return the absolute pathname corresponding to
75.Fa pathname .
76.Sh RETURN VALUES
77If
78.Fa resolvedname
79is
80.Dv NULL ,
81it will be allocated and the returned pointer can be deallocated using
82.Xr free 3 .
83The
84.Fn realpath
85function returns
86.Fa resolvedname
87on success.
88If an error occurs,
89.Fn realpath
90returns
91.Dv NULL ,
92and
93.Fa resolvedname
94was not allocated by
95.Fn realpath ,
96it will contain the pathname which caused the problem.
97.Sh ERRORS
98The function
99.Fn realpath
100may fail and set the external variable
101.Va errno
102for any of the errors specified for the library functions
103.Xr chdir 2 ,
104.Xr close 2 ,
105.Xr fchdir 2 ,
106.Xr lstat 2 ,
107.Xr malloc 3 ,
108.Xr open 2 ,
109.Xr readlink 2
110and
111.Xr getcwd 3 .
112.Sh SEE ALSO
113.Xr getcwd 3
114.Sh STANDARDS
115.Fn realpath
116first appeared in
117.St -xpg4.2
118and is part of
119.St -p1003.1-2001 .
120.Sh HISTORY
121The
122.Fn realpath
123function call first appeared in
124.Bx 4.4 .
125In
126.Nx 7.0
127the function was updated to accept a
128.Dv NULL
129pointer for the
130.Fa resolvedname
131argument.
132.Sh BUGS
133This implementation of
134.Fn realpath
135differs slightly from the Solaris implementation.
136The
137.Bx 4.4
138version always returns absolute pathnames,
139whereas the Solaris implementation will,
140under certain circumstances, return a relative
141.Fa resolvedname
142when given a relative
143.Fa pathname .
144