xref: /original-bsd/lib/libc/gen/realpath.3 (revision 3b235ced)
1.\" Copyright (c) 1994
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Jan-Simon Pendry.
6.\"
7.\" %sccs.include.redist.roff%
8.\"
9.\"     @(#)realpath.3	8.1 (Berkeley) 02/16/94
10.\"
11.Dd ""
12.Dt REALPATH 3
13.Os
14.Sh NAME
15.Nm realpath
16.Nd returns the canonicalized absolute pathname
17.Sh SYNOPSIS
18.Fd #include <sys/param.h>
19.Fd #include <stdlib.h>
20.Ft "char *"
21.Fn realpath "const char *pathname" "char resolvedname[MAXPATHLEN]"
22.Sh DESCRIPTION
23The
24.Fn realpath
25function resolves all symbolic links, extra
26.Dq /
27characters and references to
28.Pa /./
29and
30.Pa /../
31in
32.Fa pathname ,
33and copies the resulting absolute pathname into
34the memory referenced by
35.Fa resolvedname .
36The
37.Fa resolvedname
38argument
39.Em must
40refer to a buffer capable of storing at least
41.Dv MAXPATHLEN
42characters.
43.Pp
44The
45.Fn realpath
46function will resolve both absolute and relative paths
47and return the absolute pathname corresponding to
48.Fa pathname .
49All but the last component of
50.Fa pathname
51must exist when
52.Fn realpath
53is called.
54.Sh "RETURN VALUES"
55The
56.Fn realpath
57function returns
58.Fa resolved_name
59on success.
60If an error occurs,
61.Fn realpath
62returns
63.Dv NULL ,
64and
65.Fa resolved_name
66contains the pathname which caused the problem.
67.Sh ERRORS
68The function
69.Fn realpath
70may fail and set the external variable
71.Va errno
72for any of the errors specified for the library functions
73.Xr chdir 2 ,
74.Xr close 2 ,
75.Xr fchdir 2 ,
76.Xr lstat 2 ,
77.Xr open 2 ,
78.Xr readlink 2
79and
80.Xr getcwd 3 .
81.Sh CAVEATS
82This implementation of
83.Fn realpath
84differs slightly from the Solaris implementation.
85The
86.Bx 4.4
87version always returns absolute pathnames,
88whereas the Solaris implementation will,
89under certain circumstances, return a relative
90.Fa resolved_path
91when given a relative
92.Fa pathname .
93.Sh "SEE ALSO"
94.Xr getcwd 3
95.Sh HISTORY
96The
97.Fn realpath
98function call first appeared in
99.Bx 4.4 -Lite.
100