xref: /freebsd/lib/libpathconv/rel2abs.3 (revision 745c6c0431d01b4fc3247f4eac08a2181d71e008)
1.\"
2.\" Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
3.\" Copyright (c) 1999 Tama Communications Corporation. All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd December 13, 2025
27.Dt REL2ABS 3
28.Os
29.Sh NAME
30.Nm rel2abs
31.Nd make an absolute path name from a relative path name
32.Sh SYNOPSIS
33.Lb libpathconv
34.Ft "char *"
35.Fn rel2abs "const char *path" "const char *base" "char *result" "size_t size"
36.Sh DESCRIPTION
37The
38.Fn rel2abs
39function makes an absolute path name from a relative path name
40.Fa path
41based on a directory
42.Fa base
43and copies the resulting path name into the memory referenced by
44.Fa result .
45The
46.Fa result
47argument must refer to a buffer capable of storing at least
48.Fa size
49character
50
51The resulting path name may include symbolic links.
52.Fn abs2rel
53doesn't check whether or not any path exists.
54.Sh "RETURN VALUES"
55The
56.Fn rel2abs
57function returns absolute path name on success.
58If an error occurs, it returns
59.Dv NULL .
60.Sh EXAMPLES
61    char result[MAXPATHLEN];
62    char *path = rel2abs("../../src/sys", "/usr/local/lib", result, MAXPATHLEN);
63
64yields:
65
66    path == "/usr/src/sys"
67
68Similarly,
69
70    path1 = rel2abs("src/sys", "/usr", result, MAXPATHLEN);
71    path2 = rel2abs(".", "/usr/src/sys", result, MAXPATHLEN);
72
73yields:
74
75    path1 == "/usr/src/sys"
76    path2 == "/usr/src/sys"
77.Sh ERRORS
78The
79.Fn rel2abs
80function may fail and set the external variable
81.Va errno
82to indicate the error.
83.Bl -tag -width Er
84.It Bq Er EINVAL
85The
86.Fa base
87directory isn't an absolute path name or the
88.Fa size
89argument is zero.
90.It Bq Er ERANGE
91The
92.Fa size
93argument is greater than zero but smaller than the length of the pathname plus 1
94.El
95.Sh SEE ALSO
96.Xr abs2rel 3
97.Sh AUTHORS
98.An Shigio Yamaguchi (shigio@tamacom.com)
99