realpath expands all symbolic links and resolves references to
'/./', '/../' and extra '/' characters in the null
terminated string named by path and stores the canonicalized absolute
pathname in the buffer of size PATH_MAX named by resolved_path.
The resulting path will have no symbolic link, '/./' or '/../'
Never use this function. It is broken by design since it is impossible to
determine a suitable size for the output buffer. According to POSIX a buffer
of size PATH_MAX suffices, but PATH_MAX need not be a defined constant, and
may have to be obtained using pathconf(). And asking pathconf()
does not really help, since on the one hand POSIX warns that the result of
pathconf() may be huge and unsuitable for mallocing memory. And on the
other hand pathconf() may return -1 to signify that PATH_MAX is not
The libc4 and libc5 implementation contains a buffer overflow (fixed in
libc-5.4.13). Thus, suid programs like mount need a private version.
In BSD 4.4 and Solaris the limit on the pathname length is MAXPATHLEN (found in
<sys/param.h>). The SUSv2 prescribes PATH_MAX and NAME_MAX, as found in
<limits.h> or provided by the pathconf() function. A typical
source fragment would be
(But see the BUGS section.)
The BSD 4.4, Linux and SUSv2 versions always return an absolute path name.
Solaris may return a relative path name when the path argument is
relative. The prototype of realpath is given in <unistd.h> in
libc4 and libc5, but in <stdlib.h> everywhere else.