@@ -38,13 +38,13 @@ static struct cache_def {
38
38
int flags ;
39
39
int track_flags ;
40
40
int prefix_len_stat_func ;
41
- } cache ;
41
+ } default_cache ;
42
42
43
- static inline void reset_lstat_cache (void )
43
+ static inline void reset_lstat_cache (struct cache_def * cache )
44
44
{
45
- cache . path [0 ] = '\0' ;
46
- cache . len = 0 ;
47
- cache . flags = 0 ;
45
+ cache -> path [0 ] = '\0' ;
46
+ cache -> len = 0 ;
47
+ cache -> flags = 0 ;
48
48
/*
49
49
* The track_flags and prefix_len_stat_func members is only
50
50
* set by the safeguard rule inside lstat_cache()
@@ -70,34 +70,34 @@ static inline void reset_lstat_cache(void)
70
70
* of the prefix, where the cache should use the stat() function
71
71
* instead of the lstat() function to test each path component.
72
72
*/
73
- static int lstat_cache (const char * name , int len ,
73
+ static int lstat_cache (struct cache_def * cache , const char * name , int len ,
74
74
int track_flags , int prefix_len_stat_func )
75
75
{
76
76
int match_len , last_slash , last_slash_dir , previous_slash ;
77
77
int match_flags , ret_flags , save_flags , max_len , ret ;
78
78
struct stat st ;
79
79
80
- if (cache . track_flags != track_flags ||
81
- cache . prefix_len_stat_func != prefix_len_stat_func ) {
80
+ if (cache -> track_flags != track_flags ||
81
+ cache -> prefix_len_stat_func != prefix_len_stat_func ) {
82
82
/*
83
83
* As a safeguard rule we clear the cache if the
84
84
* values of track_flags and/or prefix_len_stat_func
85
85
* does not match with the last supplied values.
86
86
*/
87
- reset_lstat_cache ();
88
- cache . track_flags = track_flags ;
89
- cache . prefix_len_stat_func = prefix_len_stat_func ;
87
+ reset_lstat_cache (cache );
88
+ cache -> track_flags = track_flags ;
89
+ cache -> prefix_len_stat_func = prefix_len_stat_func ;
90
90
match_len = last_slash = 0 ;
91
91
} else {
92
92
/*
93
93
* Check to see if we have a match from the cache for
94
94
* the 2 "excluding" path types.
95
95
*/
96
96
match_len = last_slash =
97
- longest_path_match (name , len , cache . path , cache . len ,
97
+ longest_path_match (name , len , cache -> path , cache -> len ,
98
98
& previous_slash );
99
- match_flags = cache . flags & track_flags & (FL_NOENT |FL_SYMLINK );
100
- if (match_flags && match_len == cache . len )
99
+ match_flags = cache -> flags & track_flags & (FL_NOENT |FL_SYMLINK );
100
+ if (match_flags && match_len == cache -> len )
101
101
return match_flags ;
102
102
/*
103
103
* If we now have match_len > 0, we would know that
@@ -121,18 +121,18 @@ static int lstat_cache(const char *name, int len,
121
121
max_len = len < PATH_MAX ? len : PATH_MAX ;
122
122
while (match_len < max_len ) {
123
123
do {
124
- cache . path [match_len ] = name [match_len ];
124
+ cache -> path [match_len ] = name [match_len ];
125
125
match_len ++ ;
126
126
} while (match_len < max_len && name [match_len ] != '/' );
127
127
if (match_len >= max_len && !(track_flags & FL_FULLPATH ))
128
128
break ;
129
129
last_slash = match_len ;
130
- cache . path [last_slash ] = '\0' ;
130
+ cache -> path [last_slash ] = '\0' ;
131
131
132
132
if (last_slash <= prefix_len_stat_func )
133
- ret = stat (cache . path , & st );
133
+ ret = stat (cache -> path , & st );
134
134
else
135
- ret = lstat (cache . path , & st );
135
+ ret = lstat (cache -> path , & st );
136
136
137
137
if (ret ) {
138
138
ret_flags = FL_LSTATERR ;
@@ -156,9 +156,9 @@ static int lstat_cache(const char *name, int len,
156
156
*/
157
157
save_flags = ret_flags & track_flags & (FL_NOENT |FL_SYMLINK );
158
158
if (save_flags && last_slash > 0 && last_slash <= PATH_MAX ) {
159
- cache . path [last_slash ] = '\0' ;
160
- cache . len = last_slash ;
161
- cache . flags = save_flags ;
159
+ cache -> path [last_slash ] = '\0' ;
160
+ cache -> len = last_slash ;
161
+ cache -> flags = save_flags ;
162
162
} else if ((track_flags & FL_DIR ) &&
163
163
last_slash_dir > 0 && last_slash_dir <= PATH_MAX ) {
164
164
/*
@@ -172,11 +172,11 @@ static int lstat_cache(const char *name, int len,
172
172
* can still cache the path components before the last
173
173
* one (the found symlink or non-existing component).
174
174
*/
175
- cache . path [last_slash_dir ] = '\0' ;
176
- cache . len = last_slash_dir ;
177
- cache . flags = FL_DIR ;
175
+ cache -> path [last_slash_dir ] = '\0' ;
176
+ cache -> len = last_slash_dir ;
177
+ cache -> flags = FL_DIR ;
178
178
} else {
179
- reset_lstat_cache ();
179
+ reset_lstat_cache (cache );
180
180
}
181
181
return ret_flags ;
182
182
}
@@ -188,16 +188,17 @@ static int lstat_cache(const char *name, int len,
188
188
void invalidate_lstat_cache (const char * name , int len )
189
189
{
190
190
int match_len , previous_slash ;
191
+ struct cache_def * cache = & default_cache ; /* FIXME */
191
192
192
- match_len = longest_path_match (name , len , cache . path , cache . len ,
193
+ match_len = longest_path_match (name , len , cache -> path , cache -> len ,
193
194
& previous_slash );
194
195
if (len == match_len ) {
195
- if ((cache . track_flags & FL_DIR ) && previous_slash > 0 ) {
196
- cache . path [previous_slash ] = '\0' ;
197
- cache . len = previous_slash ;
198
- cache . flags = FL_DIR ;
196
+ if ((cache -> track_flags & FL_DIR ) && previous_slash > 0 ) {
197
+ cache -> path [previous_slash ] = '\0' ;
198
+ cache -> len = previous_slash ;
199
+ cache -> flags = FL_DIR ;
199
200
} else {
200
- reset_lstat_cache ();
201
+ reset_lstat_cache (cache );
201
202
}
202
203
}
203
204
}
@@ -207,7 +208,8 @@ void invalidate_lstat_cache(const char *name, int len)
207
208
*/
208
209
void clear_lstat_cache (void )
209
210
{
210
- reset_lstat_cache ();
211
+ struct cache_def * cache = & default_cache ; /* FIXME */
212
+ reset_lstat_cache (cache );
211
213
}
212
214
213
215
#define USE_ONLY_LSTAT 0
@@ -217,7 +219,8 @@ void clear_lstat_cache(void)
217
219
*/
218
220
int has_symlink_leading_path (const char * name , int len )
219
221
{
220
- return lstat_cache (name , len ,
222
+ struct cache_def * cache = & default_cache ; /* FIXME */
223
+ return lstat_cache (cache , name , len ,
221
224
FL_SYMLINK |FL_DIR , USE_ONLY_LSTAT ) &
222
225
FL_SYMLINK ;
223
226
}
@@ -228,7 +231,8 @@ int has_symlink_leading_path(const char *name, int len)
228
231
*/
229
232
int has_symlink_or_noent_leading_path (const char * name , int len )
230
233
{
231
- return lstat_cache (name , len ,
234
+ struct cache_def * cache = & default_cache ; /* FIXME */
235
+ return lstat_cache (cache , name , len ,
232
236
FL_SYMLINK |FL_NOENT |FL_DIR , USE_ONLY_LSTAT ) &
233
237
(FL_SYMLINK |FL_NOENT );
234
238
}
@@ -242,7 +246,8 @@ int has_symlink_or_noent_leading_path(const char *name, int len)
242
246
*/
243
247
int has_dirs_only_path (const char * name , int len , int prefix_len )
244
248
{
245
- return lstat_cache (name , len ,
249
+ struct cache_def * cache = & default_cache ; /* FIXME */
250
+ return lstat_cache (cache , name , len ,
246
251
FL_DIR |FL_FULLPATH , prefix_len ) &
247
252
FL_DIR ;
248
253
}
0 commit comments