xref: /dflybsd-src/lib/libc/sys/__realpath.2 (revision d8bda3d5150fb1f854f716b68f8cd606a554c06b)
1*d8bda3d5SMatthew Dillon.\" Copyright (c) 2020 The DragonFly Project.  All rights reserved.
2*d8bda3d5SMatthew Dillon.\"
3*d8bda3d5SMatthew Dillon.\" This code is derived from software contributed to The DragonFly Project
4*d8bda3d5SMatthew Dillon.\" by Matthew Dillon <dillon@backplane.com>
5*d8bda3d5SMatthew Dillon.\"
6*d8bda3d5SMatthew Dillon.\" Redistribution and use in source and binary forms, with or without
7*d8bda3d5SMatthew Dillon.\" modification, are permitted provided that the following conditions
8*d8bda3d5SMatthew Dillon.\" are met:
9*d8bda3d5SMatthew Dillon.\"
10*d8bda3d5SMatthew Dillon.\" 1. Redistributions of source code must retain the above copyright
11*d8bda3d5SMatthew Dillon.\"    notice, this list of conditions and the following disclaimer.
12*d8bda3d5SMatthew Dillon.\" 2. Redistributions in binary form must reproduce the above copyright
13*d8bda3d5SMatthew Dillon.\"    notice, this list of conditions and the following disclaimer in
14*d8bda3d5SMatthew Dillon.\"    the documentation and/or other materials provided with the
15*d8bda3d5SMatthew Dillon.\"    distribution.
16*d8bda3d5SMatthew Dillon.\" 3. Neither the name of The DragonFly Project nor the names of its
17*d8bda3d5SMatthew Dillon.\"    contributors may be used to endorse or promote products derived
18*d8bda3d5SMatthew Dillon.\"    from this software without specific, prior written permission.
19*d8bda3d5SMatthew Dillon.\"
20*d8bda3d5SMatthew Dillon.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*d8bda3d5SMatthew Dillon.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*d8bda3d5SMatthew Dillon.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*d8bda3d5SMatthew Dillon.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24*d8bda3d5SMatthew Dillon.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*d8bda3d5SMatthew Dillon.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*d8bda3d5SMatthew Dillon.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*d8bda3d5SMatthew Dillon.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*d8bda3d5SMatthew Dillon.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*d8bda3d5SMatthew Dillon.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30*d8bda3d5SMatthew Dillon.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*d8bda3d5SMatthew Dillon.\" SUCH DAMAGE.
32*d8bda3d5SMatthew Dillon.Dd February 2, 2020
33*d8bda3d5SMatthew Dillon.Dt __REALPATH 2
34*d8bda3d5SMatthew Dillon.Os
35*d8bda3d5SMatthew Dillon.Sh NAME
36*d8bda3d5SMatthew Dillon.Nm __realpath
37*d8bda3d5SMatthew Dillon.Nd resolves the canonicalized absolute pathname
38*d8bda3d5SMatthew Dillon.Sh LIBRARY
39*d8bda3d5SMatthew Dillon.Lb libc
40*d8bda3d5SMatthew Dillon.Sh SYNOPSIS
41*d8bda3d5SMatthew Dillon.Ft "int"
42*d8bda3d5SMatthew Dillon.Fn __realpath "const char * restrict pathname" "char * restrict resolved_path" "size_t len"
43*d8bda3d5SMatthew Dillon.Sh DESCRIPTION
44*d8bda3d5SMatthew DillonThe
45*d8bda3d5SMatthew Dillon.Fn __realpath
46*d8bda3d5SMatthew Dillonsystem call is used to support the libc
47*d8bda3d5SMatthew Dillon.Fn realpath
48*d8bda3d5SMatthew Dillonlibrary call.
49*d8bda3d5SMatthew DillonIt basically does the same thing but with a lower-level system-call
50*d8bda3d5SMatthew Dilloncompatible API.
51*d8bda3d5SMatthew DillonThe system call differs from the libc function as follows:
52*d8bda3d5SMatthew DillonIt requires that the target buffer and the size of the target
53*d8bda3d5SMatthew Dillonbuffer be supplied, it does not (obviously) allocate a target buffer if NULL
54*d8bda3d5SMatthew Dillonis supplied, and it returns the string length of the target buffer (not
55*d8bda3d5SMatthew Dillonincluding the terminator) or -1.
56*d8bda3d5SMatthew DillonIf a failure occurs, the target buffer will not be modified (whereas it is
57*d8bda3d5SMatthew Dillonin the libc function).
58*d8bda3d5SMatthew Dillon.Pp
59*d8bda3d5SMatthew DillonThe system call will resolves all symbolic links, extra
60*d8bda3d5SMatthew Dillon.Dq /
61*d8bda3d5SMatthew Dilloncharacters and references to
62*d8bda3d5SMatthew Dillon.Pa /./
63*d8bda3d5SMatthew Dillonand
64*d8bda3d5SMatthew Dillon.Pa /../
65*d8bda3d5SMatthew Dillonin
66*d8bda3d5SMatthew Dillon.Fa pathname ,
67*d8bda3d5SMatthew Dillonand copies the resulting absolute pathname into
68*d8bda3d5SMatthew Dillonthe memory pointed to by
69*d8bda3d5SMatthew Dillon.Fa resolved_path .
70*d8bda3d5SMatthew DillonThe
71*d8bda3d5SMatthew Dillon.Fa resolved_path
72*d8bda3d5SMatthew Dillonargument
73*d8bda3d5SMatthew Dillon.Em must
74*d8bda3d5SMatthew Dillonpoint to a buffer capable of storing at least
75*d8bda3d5SMatthew Dillon.Dv len
76*d8bda3d5SMatthew Dilloncharacters, and may not be
77*d8bda3d5SMatthew Dillon.Dv NULL .
78*d8bda3d5SMatthew Dillon.Pp
79*d8bda3d5SMatthew DillonThe
80*d8bda3d5SMatthew Dillon.Fn __realpath
81*d8bda3d5SMatthew Dillonfunction will resolve both absolute and relative paths
82*d8bda3d5SMatthew Dillonand return the absolute pathname corresponding to
83*d8bda3d5SMatthew Dillon.Fa pathname .
84*d8bda3d5SMatthew DillonAll components of
85*d8bda3d5SMatthew Dillon.Fa pathname
86*d8bda3d5SMatthew Dillonmust exist when
87*d8bda3d5SMatthew Dillon.Fn __realpath
88*d8bda3d5SMatthew Dillonis called, and all but the last component must name either directories or
89*d8bda3d5SMatthew Dillonsymlinks pointing to the directories.
90*d8bda3d5SMatthew Dillon.Sh "RETURN VALUES"
91*d8bda3d5SMatthew DillonThe
92*d8bda3d5SMatthew Dillon.Fn realpath
93*d8bda3d5SMatthew Dillonfunction returns
94*d8bda3d5SMatthew Dillonthe string length of the path stored in the target buffer, not including
95*d8bda3d5SMatthew Dillonthe terminator, or -1 on failure.
96*d8bda3d5SMatthew Dillon.Sh ERRORS
97*d8bda3d5SMatthew DillonThe function
98*d8bda3d5SMatthew Dillonmay fail and set the external variable
99*d8bda3d5SMatthew Dillon.Va errno
100*d8bda3d5SMatthew Dillonfor any of the errors specified for the library function
101*d8bda3d5SMatthew Dillon.Xr realpath 3 .
102*d8bda3d5SMatthew Dillon.Sh SEE ALSO
103*d8bda3d5SMatthew Dillon.Xr realpath 3
104*d8bda3d5SMatthew Dillon.Sh HISTORY
105*d8bda3d5SMatthew DillonThe
106*d8bda3d5SMatthew Dillon.Fn __realpath
107*d8bda3d5SMatthew Dillonfunction first appeared in
108*d8bda3d5SMatthew Dillon.Dx 5.7 .
109*d8bda3d5SMatthew Dillon.Sh CAVEATS
110*d8bda3d5SMatthew DillonThis is the system call version of the libc
111*d8bda3d5SMatthew Dillon.Fn realpath
112*d8bda3d5SMatthew Dillonfunction, but is not a replacement for the libc function due to
113*d8bda3d5SMatthew Dillonnecessary API differences.
114