1LSTAT(P) POSIX Programmer's Manual LSTAT(P)
2
3
4
6 lstat - get symbolic link status
7
9 #include <sys/stat.h>
10
11 int lstat(const char *restrict path, struct stat *restrict buf);
12
13
15 The lstat() function shall be equivalent to stat(), except when path
16 refers to a symbolic link. In that case lstat() shall return informa‐
17 tion about the link, while stat() shall return information about the
18 file the link references.
19
20 For symbolic links, the st_mode member shall contain meaningful infor‐
21 mation when used with the file type macros, and the st_size member
22 shall contain the length of the pathname contained in the symbolic
23 link. File mode bits and the contents of the remaining members of the
24 stat structure are unspecified. The value returned in the st_size mem‐
25 ber is the length of the contents of the symbolic link, and does not
26 count any trailing null.
27
29 Upon successful completion, lstat() shall return 0. Otherwise, it shall
30 return -1 and set errno to indicate the error.
31
33 The lstat() function shall fail if:
34
35 EACCES A component of the path prefix denies search permission.
36
37 EIO An error occurred while reading from the file system.
38
39 ELOOP A loop exists in symbolic links encountered during resolution of
40 the path argument.
41
42 ENAMETOOLONG
43 The length of a pathname exceeds {PATH_MAX} or a pathname compo‐
44 nent is longer than {NAME_MAX}.
45
46 ENOTDIR
47 A component of the path prefix is not a directory.
48
49 ENOENT A component of path does not name an existing file or path is an
50 empty string.
51
52 EOVERFLOW
53 The file size in bytes or the number of blocks allocated to the
54 file or the file serial number cannot be represented correctly
55 in the structure pointed to by buf.
56
57
58 The lstat() function may fail if:
59
60 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
61 resolution of the path argument.
62
63 ENAMETOOLONG
64 As a result of encountering a symbolic link in resolution of the
65 path argument, the length of the substituted pathname string
66 exceeded {PATH_MAX}.
67
68 EOVERFLOW
69 One of the members is too large to store into the structure
70 pointed to by the buf argument.
71
72
73 The following sections are informative.
74
76 Obtaining Symbolic Link Status Information
77 The following example shows how to obtain status information for a sym‐
78 bolic link named /modules/pass1. The structure variable buffer is
79 defined for the stat structure. If the path argument specified the
80 filename for the file pointed to by the symbolic link (
81 /home/cnd/mod1), the results of calling the function would be the same
82 as those returned by a call to the stat() function.
83
84
85 #include <sys/stat.h>
86
87
88 struct stat buffer;
89 int status;
90 ...
91 status = lstat("/modules/pass1", &buffer);
92
94 None.
95
97 The lstat() function is not required to update the time-related fields
98 if the named file is not a symbolic link. While the st_uid, st_gid,
99 st_atime, st_mtime, and st_ctime members of the stat structure may
100 apply to a symbolic link, they are not required to do so. No functions
101 in IEEE Std 1003.1-2001 are required to maintain any of these time
102 fields.
103
105 None.
106
108 fstat() , readlink() , stat() , symlink() , the Base Definitions volume
109 of IEEE Std 1003.1-2001, <sys/stat.h>
110
112 Portions of this text are reprinted and reproduced in electronic form
113 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
114 -- Portable Operating System Interface (POSIX), The Open Group Base
115 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
116 Electrical and Electronics Engineers, Inc and The Open Group. In the
117 event of any discrepancy between this version and the original IEEE and
118 The Open Group Standard, the original IEEE and The Open Group Standard
119 is the referee document. The original Standard can be obtained online
120 at http://www.opengroup.org/unix/online.html .
121
122
123
124IEEE/The Open Group 2003 LSTAT(P)