xref: /freebsd/lib/libc/stdlib/realpath.3 (revision da5dfd565ffbe252e68888d493f86df5bf7318f1)
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.\" 4. Neither the name of the University nor the names of its contributors
16d01a28e2SPeter Wemm.\"    may be used to endorse or promote products derived from this software
17d01a28e2SPeter Wemm.\"    without specific prior written permission.
18d01a28e2SPeter Wemm.\"
19d01a28e2SPeter Wemm.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20d01a28e2SPeter Wemm.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21d01a28e2SPeter Wemm.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22d01a28e2SPeter Wemm.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23d01a28e2SPeter Wemm.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24d01a28e2SPeter Wemm.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25d01a28e2SPeter Wemm.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26d01a28e2SPeter Wemm.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27d01a28e2SPeter Wemm.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28d01a28e2SPeter Wemm.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29d01a28e2SPeter Wemm.\" SUCH DAMAGE.
30d01a28e2SPeter Wemm.\"
31d01a28e2SPeter Wemm.\"     @(#)realpath.3	8.2 (Berkeley) 2/16/94
327f3dea24SPeter Wemm.\" $FreeBSD$
33d01a28e2SPeter Wemm.\"
34fdbe55fcSKonstantin Belousov.Dd May 11, 2012
35d01a28e2SPeter Wemm.Dt REALPATH 3
36d01a28e2SPeter Wemm.Os
37d01a28e2SPeter Wemm.Sh NAME
38d01a28e2SPeter Wemm.Nm realpath
39d01a28e2SPeter Wemm.Nd returns the canonicalized absolute pathname
4025bb73e0SAlexey Zelkin.Sh LIBRARY
4125bb73e0SAlexey Zelkin.Lb libc
42d01a28e2SPeter Wemm.Sh SYNOPSIS
438aefde06SJeroen Ruigrok van der Werven.In stdlib.h
44d01a28e2SPeter Wemm.Ft "char *"
45*da5dfd56SKevin Lo.Fn realpath "const char * restrict pathname" "char * restrict resolved_path"
46d01a28e2SPeter Wemm.Sh DESCRIPTION
47d01a28e2SPeter WemmThe
48d01a28e2SPeter Wemm.Fn realpath
49d01a28e2SPeter Wemmfunction resolves all symbolic links, extra
50d01a28e2SPeter Wemm.Dq /
51d01a28e2SPeter Wemmcharacters and references to
52d01a28e2SPeter Wemm.Pa /./
53d01a28e2SPeter Wemmand
54d01a28e2SPeter Wemm.Pa /../
55d01a28e2SPeter Wemmin
56d01a28e2SPeter Wemm.Fa pathname ,
57d01a28e2SPeter Wemmand copies the resulting absolute pathname into
58431c9bf2SKonstantin Belousovthe memory pointed to by
59cfc2d91bSChris Costello.Fa resolved_path .
60d01a28e2SPeter WemmThe
61cfc2d91bSChris Costello.Fa resolved_path
62d01a28e2SPeter Wemmargument
63d01a28e2SPeter Wemm.Em must
64431c9bf2SKonstantin Belousovpoint to a buffer capable of storing at least
65de216a83SJohan Karlsson.Dv PATH_MAX
669d79ec20SKonstantin Belousovcharacters, or be
679d79ec20SKonstantin Belousov.Dv NULL .
68d01a28e2SPeter Wemm.Pp
69d01a28e2SPeter WemmThe
70d01a28e2SPeter Wemm.Fn realpath
71d01a28e2SPeter Wemmfunction will resolve both absolute and relative paths
72d01a28e2SPeter Wemmand return the absolute pathname corresponding to
73d01a28e2SPeter Wemm.Fa pathname .
74fdbe55fcSKonstantin BelousovAll components of
75d01a28e2SPeter Wemm.Fa pathname
76d01a28e2SPeter Wemmmust exist when
77d01a28e2SPeter Wemm.Fn realpath
78fdbe55fcSKonstantin Belousovis called, and all but the last component must name either directories or
79fdbe55fcSKonstantin Belousovsymlinks pointing to the directories.
80d01a28e2SPeter Wemm.Sh "RETURN VALUES"
81d01a28e2SPeter WemmThe
82d01a28e2SPeter Wemm.Fn realpath
83d01a28e2SPeter Wemmfunction returns
84cfc2d91bSChris Costello.Fa resolved_path
85d01a28e2SPeter Wemmon success.
869d79ec20SKonstantin BelousovIf the function was supplied
879d79ec20SKonstantin Belousov.Dv NULL
889d79ec20SKonstantin Belousovas
899d79ec20SKonstantin Belousov.Fa resolved_path ,
909d79ec20SKonstantin Belousovand operation did not cause errors, the returned value is
919d79ec20SKonstantin Belousova null-terminated string in a buffer allocated by a call to
929d79ec20SKonstantin Belousov.Fn malloc 3 .
93d01a28e2SPeter WemmIf an error occurs,
94d01a28e2SPeter Wemm.Fn realpath
95d01a28e2SPeter Wemmreturns
96d01a28e2SPeter Wemm.Dv NULL ,
977e36a19dSKonstantin Belousovand if
98cfc2d91bSChris Costello.Fa resolved_path
997e36a19dSKonstantin Belousovis not
1009d79ec20SKonstantin Belousov.Dv NULL ,
1017e36a19dSKonstantin Belousovthe array that it points to contains the pathname which caused the problem.
102d01a28e2SPeter Wemm.Sh ERRORS
103d01a28e2SPeter WemmThe function
104d01a28e2SPeter Wemm.Fn realpath
105d01a28e2SPeter Wemmmay fail and set the external variable
106d01a28e2SPeter Wemm.Va errno
107d01a28e2SPeter Wemmfor any of the errors specified for the library functions
108d01a28e2SPeter Wemm.Xr lstat 2 ,
109d01a28e2SPeter Wemm.Xr readlink 2
110d01a28e2SPeter Wemmand
111d01a28e2SPeter Wemm.Xr getcwd 3 .
1120afc94c1SUlrich Spörlein.Sh SEE ALSO
1130afc94c1SUlrich Spörlein.Xr getcwd 3
11401e14bffSAndrey A. Chernov.\" .Sh STANDARDS
11501e14bffSAndrey A. Chernov.\" The
11601e14bffSAndrey A. Chernov.\" .Fn realpath
11701e14bffSAndrey A. Chernov.\" function conforms to
11801e14bffSAndrey A. Chernov.\" .St -p1003.1-2001 .
1190afc94c1SUlrich Spörlein.Sh HISTORY
1200afc94c1SUlrich SpörleinThe
1210afc94c1SUlrich Spörlein.Fn realpath
1220afc94c1SUlrich Spörleinfunction first appeared in
1230afc94c1SUlrich Spörlein.Bx 4.4 .
124d01a28e2SPeter Wemm.Sh CAVEATS
125d01a28e2SPeter WemmThis implementation of
126d01a28e2SPeter Wemm.Fn realpath
127d01a28e2SPeter Wemmdiffers slightly from the Solaris implementation.
128d01a28e2SPeter WemmThe
129d01a28e2SPeter Wemm.Bx 4.4
130d01a28e2SPeter Wemmversion always returns absolute pathnames,
131d01a28e2SPeter Wemmwhereas the Solaris implementation will,
132d01a28e2SPeter Wemmunder certain circumstances, return a relative
133d01a28e2SPeter Wemm.Fa resolved_path
134d01a28e2SPeter Wemmwhen given a relative
135d01a28e2SPeter Wemm.Fa pathname .
136