1REALPATH(3)                Linux Programmer's Manual               REALPATH(3)
2
3
4

NAME

6       realpath - return the canonicalized absolute pathname
7

SYNOPSIS

9       #include <limits.h>
10       #include <stdlib.h>
11
12       char *realpath(const char *path, char *resolved_path);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       realpath():
17           _XOPEN_SOURCE >= 500
18               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
19               || /* Glibc versions <= 2.19: */ _BSD_SOURCE
20

DESCRIPTION

22       realpath()  expands  all symbolic links and resolves references to /./,
23       /../ and extra '/' characters in the null-terminated  string  named  by
24       path to produce a canonicalized absolute pathname.  The resulting path‐
25       name is stored as a null-terminated string, up to a maximum of PATH_MAX
26       bytes,  in  the buffer pointed to by resolved_path.  The resulting path
27       will have no symbolic link, /./ or /../ components.
28
29       If resolved_path is specified as NULL, then realpath()  uses  malloc(3)
30       to allocate a buffer of up to PATH_MAX bytes to hold the resolved path‐
31       name, and returns a pointer to this buffer.  The caller should  deallo‐
32       cate this buffer using free(3).
33

RETURN VALUE

35       If   there   is   no   error,  realpath()  returns  a  pointer  to  the
36       resolved_path.
37
38       Otherwise, it returns NULL, the contents of the array resolved_path are
39       undefined, and errno is set to indicate the error.
40

ERRORS

42       EACCES Read or search permission was denied for a component of the path
43              prefix.
44
45       EINVAL path is NULL.  (In glibc versions before 2.3, this error is also
46              returned if resolved_path is NULL.)
47
48       EIO    An I/O error occurred while reading from the filesystem.
49
50       ELOOP  Too  many  symbolic  links  were  encountered in translating the
51              pathname.
52
53       ENAMETOOLONG
54              A component of a pathname exceeded NAME_MAX  characters,  or  an
55              entire pathname exceeded PATH_MAX characters.
56
57       ENOENT The named file does not exist.
58
59       ENOMEM Out of memory.
60
61       ENOTDIR
62              A component of the path prefix is not a directory.
63

ATTRIBUTES

65       For   an   explanation   of   the  terms  used  in  this  section,  see
66       attributes(7).
67
68       ┌───────────┬───────────────┬─────────┐
69Interface  Attribute     Value   
70       ├───────────┼───────────────┼─────────┤
71realpath() │ Thread safety │ MT-Safe │
72       └───────────┴───────────────┴─────────┘

CONFORMING TO

74       4.4BSD, POSIX.1-2001.
75
76       POSIX.1-2001 says that the behavior if resolved_path is NULL is  imple‐
77       mentation-defined.   POSIX.1-2008  specifies  the behavior described in
78       this page.
79

NOTES

81       In 4.4BSD and Solaris, the limit on the pathname length  is  MAXPATHLEN
82       (found  in  <sys/param.h>).  SUSv2 prescribes PATH_MAX and NAME_MAX, as
83       found in <limits.h> or provided by the pathconf(3) function.  A typical
84       source fragment would be
85
86           #ifdef PATH_MAX
87             path_max = PATH_MAX;
88           #else
89             path_max = pathconf(path, _PC_PATH_MAX);
90             if (path_max <= 0)
91               path_max = 4096;
92           #endif
93
94       (But see the BUGS section.)
95
96   GNU extensions
97       If the call fails with either EACCES or ENOENT and resolved_path is not
98       NULL, then the prefix of path that is not readable or does not exist is
99       returned in resolved_path.
100

BUGS

102       The POSIX.1-2001 standard version of this function is broken by design,
103       since it is impossible to determine a suitable size for the output buf‐
104       fer,  resolved_path.   According  to  POSIX.1-2001  a  buffer  of  size
105       PATH_MAX suffices, but PATH_MAX need not be a defined constant, and may
106       have to be obtained using pathconf(3).  And asking pathconf(3) does not
107       really help, since, on the one hand POSIX  warns  that  the  result  of
108       pathconf(3) may be huge and unsuitable for mallocing memory, and on the
109       other hand pathconf(3) may return -1 to signify that  PATH_MAX  is  not
110       bounded.    The  resolved_path == NULL  feature,  not  standardized  in
111       POSIX.1-2001, but standardized  in  POSIX.1-2008,  allows  this  design
112       problem to be avoided.
113

SEE ALSO

115       realpath(1),  readlink(2),  canonicalize_file_name(3), getcwd(3), path‐
116       conf(3), sysconf(3)
117

COLOPHON

119       This page is part of release 5.02 of the Linux  man-pages  project.   A
120       description  of  the project, information about reporting bugs, and the
121       latest    version    of    this    page,    can     be     found     at
122       https://www.kernel.org/doc/man-pages/.
123
124
125
126                                  2017-09-15                       REALPATH(3)
Impressum