This source file includes following definitions.
- orig_fstatat
- normal_fstatat
- rpl_fstatat
- stat_func
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #define __need_system_sys_stat_h
24 #include <config.h>
25
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #undef __need_system_sys_stat_h
30
31 #if HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG
32 static int
33 orig_fstatat (int fd, char const *filename, struct stat *buf, int flags)
34 {
35 return fstatat (fd, filename, buf, flags);
36 }
37 #endif
38
39 #ifdef __osf__
40
41
42
43 # include "sys/stat.h"
44 #else
45 # include <sys/stat.h>
46 #endif
47
48 #include "stat-time.h"
49
50 #include <errno.h>
51 #include <fcntl.h>
52 #include <stdlib.h>
53 #include <string.h>
54
55 #if HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG
56
57 # ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK
58 # define LSTAT_FOLLOWS_SLASHED_SYMLINK 0
59 # endif
60
61 static int
62 normal_fstatat (int fd, char const *file, struct stat *st, int flag)
63 {
64 return stat_time_normalize (orig_fstatat (fd, file, st, flag), st);
65 }
66
67
68
69
70
71
72
73
74
75
76 int
77 rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
78 {
79 int result = normal_fstatat (fd, file, st, flag);
80 size_t len;
81
82 if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0)
83 return result;
84 len = strlen (file);
85 if (flag & AT_SYMLINK_NOFOLLOW)
86 {
87
88 if (file[len - 1] != '/' || S_ISDIR (st->st_mode))
89 return 0;
90 if (!S_ISLNK (st->st_mode))
91 {
92 errno = ENOTDIR;
93 return -1;
94 }
95 result = normal_fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW);
96 }
97
98 if (result == 0 && !S_ISDIR (st->st_mode) && file[len - 1] == '/')
99 {
100 errno = ENOTDIR;
101 return -1;
102 }
103 return result;
104 }
105
106 #else
107
108
109
110
111
112
113 static int
114 stat_func (char const *name, struct stat *st)
115 {
116 return stat (name, st);
117 }
118
119
120
121 # if !HAVE_LSTAT
122 # undef lstat
123 # define lstat stat_func
124 # endif
125
126
127
128
129
130
131
132
133
134 # define AT_FUNC_NAME fstatat
135 # define AT_FUNC_F1 lstat
136 # define AT_FUNC_F2 stat_func
137 # define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
138 # define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat *st, int flag
139 # define AT_FUNC_POST_FILE_ARGS , st
140 # include "at-func.c"
141 # undef AT_FUNC_NAME
142 # undef AT_FUNC_F1
143 # undef AT_FUNC_F2
144 # undef AT_FUNC_USE_F1_COND
145 # undef AT_FUNC_POST_FILE_PARAM_DECLS
146 # undef AT_FUNC_POST_FILE_ARGS
147
148 #endif