1REALPATH(P) POSIX Programmer's Manual REALPATH(P)
2
3
4
6 realpath - resolve a pathname
7
9 #include <stdlib.h>
10
11 char *realpath(const char *restrict file_name,
12 char *restrict resolved_name);
13
14
16 The realpath() function shall derive, from the pathname pointed to by
17 file_name, an absolute pathname that names the same file, whose resolu‐
18 tion does not involve '.' , '..' , or symbolic links. The generated
19 pathname shall be stored as a null-terminated string, up to a maximum
20 of {PATH_MAX} bytes, in the buffer pointed to by resolved_name.
21
22 If resolved_name is a null pointer, the behavior of realpath() is
23 implementation-defined.
24
26 Upon successful completion, realpath() shall return a pointer to the
27 resolved name. Otherwise, realpath() shall return a null pointer and
28 set errno to indicate the error, and the contents of the buffer pointed
29 to by resolved_name are undefined.
30
32 The realpath() function shall fail if:
33
34 EACCES Read or search permission was denied for a component of
35 file_name.
36
37 EINVAL The file_name argument is a null pointer.
38
39 EIO An error occurred while reading from the file system.
40
41 ELOOP A loop exists in symbolic links encountered during resolution of
42 the path argument.
43
44 ENAMETOOLONG
45 The length of the file_name argument exceeds {PATH_MAX} or a
46 pathname component is longer than {NAME_MAX}.
47
48 ENOENT A component of file_name does not name an existing file or
49 file_name points to an empty string.
50
51 ENOTDIR
52 A component of the path prefix is not a directory.
53
54
55 The realpath() function may fail if:
56
57 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
58 resolution of the path argument.
59
60 ENAMETOOLONG
61 Pathname resolution of a symbolic link produced an intermediate
62 result whose length exceeds {PATH_MAX}.
63
64 ENOMEM Insufficient storage space is available.
65
66
67 The following sections are informative.
68
70 Generating an Absolute Pathname
71 The following example generates an absolute pathname for the file iden‐
72 tified by the symlinkpath argument. The generated pathname is stored in
73 the actualpath array.
74
75
76 #include <stdlib.h>
77 ...
78 char *symlinkpath = "/tmp/symlink/file";
79 char actualpath [PATH_MAX+1];
80 char *ptr;
81
82
83 ptr = realpath(symlinkpath, actualpath);
84
86 None.
87
89 Since the maximum pathname length is arbitrary unless {PATH_MAX} is
90 defined, an application generally cannot supply a resolved_name buffer
91 with size {{PATH_MAX}+1}.
92
94 In the future, passing a null pointer to realpath() for the
95 resolved_name argument may be defined to have realpath() allocate space
96 for the generated pathname.
97
99 getcwd() , sysconf() , the Base Definitions volume of
100 IEEE Std 1003.1-2001, <stdlib.h>
101
103 Portions of this text are reprinted and reproduced in electronic form
104 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
105 -- Portable Operating System Interface (POSIX), The Open Group Base
106 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
107 Electrical and Electronics Engineers, Inc and The Open Group. In the
108 event of any discrepancy between this version and the original IEEE and
109 The Open Group Standard, the original IEEE and The Open Group Standard
110 is the referee document. The original Standard can be obtained online
111 at http://www.opengroup.org/unix/online.html .
112
113
114
115IEEE/The Open Group 2003 REALPATH(P)