xref: /freebsd/lib/libpathconv/rel2abs.3 (revision d21e322d563e0fd1f92c22205c2ced4bcd22dc23)
10f7f3352SJulian Elischer.\"
20f7f3352SJulian Elischer.\" Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
30f7f3352SJulian Elischer.\" Copyright (c) 1999 Tama Communications Corporation. All rights reserved.
40f7f3352SJulian Elischer.\"
50f7f3352SJulian Elischer.\" Redistribution and use in source and binary forms, with or without
60f7f3352SJulian Elischer.\" modification, are permitted provided that the following conditions
70f7f3352SJulian Elischer.\" are met:
80f7f3352SJulian Elischer.\" 1. Redistributions of source code must retain the above copyright
90f7f3352SJulian Elischer.\"    notice, this list of conditions and the following disclaimer.
100f7f3352SJulian Elischer.\" 2. Redistributions in binary form must reproduce the above copyright
110f7f3352SJulian Elischer.\"    notice, this list of conditions and the following disclaimer in the
120f7f3352SJulian Elischer.\"    documentation and/or other materials provided with the distribution.
130f7f3352SJulian Elischer.\"
140f7f3352SJulian Elischer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
150f7f3352SJulian Elischer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160f7f3352SJulian Elischer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
170f7f3352SJulian Elischer.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
180f7f3352SJulian Elischer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
190f7f3352SJulian Elischer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
200f7f3352SJulian Elischer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
210f7f3352SJulian Elischer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
220f7f3352SJulian Elischer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
230f7f3352SJulian Elischer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
240f7f3352SJulian Elischer.\" SUCH DAMAGE.
250f7f3352SJulian Elischer.\"
26948168c7SGordon Bergling.Dd August 7, 2022
270f7f3352SJulian Elischer.Dt REL2ABS 3
280f7f3352SJulian Elischer.Os
290f7f3352SJulian Elischer.Sh NAME
300f7f3352SJulian Elischer.Nm rel2abs
310f7f3352SJulian Elischer.Nd make an absolute path name from a relative path name
320f7f3352SJulian Elischer.Sh SYNOPSIS
330f7f3352SJulian Elischer.Ft "char *"
340f7f3352SJulian Elischer.Fn rel2abs "const char *path" "const char *base" "char *result" "size_t size"
350f7f3352SJulian Elischer.Sh DESCRIPTION
360f7f3352SJulian ElischerThe
370f7f3352SJulian Elischer.Fn rel2abs
380f7f3352SJulian Elischerfunction makes an absolute path name from a relative path name
390f7f3352SJulian Elischer.Fa path
400f7f3352SJulian Elischerbased on a directory
410f7f3352SJulian Elischer.Fa base
420f7f3352SJulian Elischerand copies the resulting path name into the memory referenced by
430f7f3352SJulian Elischer.Fa result .
440f7f3352SJulian ElischerThe
450f7f3352SJulian Elischer.Fa result
460f7f3352SJulian Elischerargument must refer to a buffer capable of storing at least
470f7f3352SJulian Elischer.Fa size
480f7f3352SJulian Elischercharacter
490f7f3352SJulian Elischer
500f7f3352SJulian ElischerThe resulting path name may include symbolic links.
510f7f3352SJulian Elischer.Fn abs2rel
520f7f3352SJulian Elischerdoesn't check whether or not any path exists.
530f7f3352SJulian Elischer.Sh "RETURN VALUES"
540f7f3352SJulian ElischerThe
550f7f3352SJulian Elischer.Fn rel2abs
560f7f3352SJulian Elischerfunction returns absolute path name on success.
570f7f3352SJulian ElischerIf an error occurs, it returns
580f7f3352SJulian Elischer.Dv NULL .
5909451711SGordon Bergling.Sh EXAMPLES
6009451711SGordon Bergling    char result[MAXPATHLEN];
6109451711SGordon Bergling    char *path = rel2abs("../../src/sys", "/usr/local/lib", result, MAXPATHLEN);
6209451711SGordon Bergling
6309451711SGordon Berglingyields:
6409451711SGordon Bergling
6509451711SGordon Bergling    path == "/usr/src/sys"
6609451711SGordon Bergling
6709451711SGordon BerglingSimilarly,
6809451711SGordon Bergling
6909451711SGordon Bergling    path1 = rel2abs("src/sys", "/usr", result, MAXPATHLEN);
7009451711SGordon Bergling    path2 = rel2abs(".", "/usr/src/sys", result, MAXPATHLEN);
7109451711SGordon Bergling
7209451711SGordon Berglingyields:
7309451711SGordon Bergling
7409451711SGordon Bergling    path1 == "/usr/src/sys"
7509451711SGordon Bergling    path2 == "/usr/src/sys"
760f7f3352SJulian Elischer.Sh ERRORS
770f7f3352SJulian ElischerThe
780f7f3352SJulian Elischer.Fn rel2abs
790f7f3352SJulian Elischerfunction may fail and set the external variable
800f7f3352SJulian Elischer.Va errno
810f7f3352SJulian Elischerto indicate the error.
820f7f3352SJulian Elischer.Bl -tag -width Er
830f7f3352SJulian Elischer.It Bq Er EINVAL
840f7f3352SJulian ElischerThe
850f7f3352SJulian Elischer.Fa base
860f7f3352SJulian Elischerdirectory isn't an absolute path name or the
870f7f3352SJulian Elischer.Fa size
880f7f3352SJulian Elischerargument is zero.
890f7f3352SJulian Elischer.It Bq Er ERANGE
900f7f3352SJulian ElischerThe
910f7f3352SJulian Elischer.Fa size
920f7f3352SJulian Elischerargument is greater than zero but smaller than the length of the pathname plus 1
93*d21e322dSGraham Percival.El
9409451711SGordon Bergling.Sh SEE ALSO
950f7f3352SJulian Elischer.Xr abs2rel 3
960f7f3352SJulian Elischer.Sh AUTHORS
9709451711SGordon Bergling.An Shigio Yamaguchi (shigio@tamacom.com)
98