@@ -21,12 +21,6 @@ static int copy_file(const char *fromfile, const char *tofile, bool force);
21
21
static int win32_pghardlink (const char * src , const char * dst );
22
22
#endif
23
23
24
- #ifndef HAVE_SCANDIR
25
- static int pg_scandir_internal (const char * dirname ,
26
- struct dirent * * * namelist ,
27
- int (* selector ) (const struct dirent * ));
28
- #endif
29
-
30
24
31
25
/*
32
26
* copyAndUpdateFile()
@@ -228,59 +222,18 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
228
222
229
223
230
224
/*
231
- * pg_scandir()
232
- *
233
- * Wrapper for portable scandir functionality
234
- */
235
- int
236
- pg_scandir (const char * dirname ,
237
- struct dirent * * * namelist ,
238
- int (* selector ) (const struct dirent * ))
239
- {
240
- #ifndef HAVE_SCANDIR
241
- return pg_scandir_internal (dirname , namelist , selector );
242
-
243
- /*
244
- * scandir() is originally from BSD 4.3, which had the third argument as
245
- * non-const. Linux and other C libraries have updated it to use a const.
246
- * http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg002
247
- * 14.html
248
- *
249
- * Here we try to guess which libc's need const, and which don't. The net
250
- * goal here is to try to suppress a compiler warning due to a prototype
251
- * mismatch of const usage. Ideally we would do this via autoconf, but
252
- * autoconf doesn't have a suitable builtin test and it seems overkill to
253
- * add one just to avoid a warning.
254
- */
255
- #elif defined(__FreeBSD__ ) || defined(__bsdi__ ) || defined(__darwin__ ) || defined(__OpenBSD__ )
256
- /* no const */
257
- return scandir (dirname , namelist , (int (* ) (struct dirent * )) selector , NULL );
258
- #else
259
- /* use const */
260
- return scandir (dirname , namelist , selector , NULL );
261
- #endif
262
- }
263
-
264
-
265
- #ifndef HAVE_SCANDIR
266
- /*
267
- * pg_scandir_internal()
268
- *
269
- * Implement our own scandir() on platforms that don't have it.
225
+ * load_directory()
270
226
*
271
227
* Returns count of files that meet the selection criteria coded in
272
228
* the function pointed to by selector. Creates an array of pointers
273
229
* to dirent structures. Address of array returned in namelist.
274
230
*
275
231
* Note that the number of dirent structures needed is dynamically
276
232
* allocated using realloc. Realloc can be inefficient if invoked a
277
- * large number of times. Its use in pg_upgrade is to find filesystem
278
- * filenames that have extended beyond the initial segment (file.1,
279
- * .2, etc.) and should therefore be invoked a small number of times.
233
+ * large number of times.
280
234
*/
281
- static int
282
- pg_scandir_internal (const char * dirname ,
283
- struct dirent * * * namelist , int (* selector ) (const struct dirent * ))
235
+ int
236
+ load_directory (const char * dirname , struct dirent * * * namelist )
284
237
{
285
238
DIR * dirdesc ;
286
239
struct dirent * direntry ;
@@ -295,42 +248,37 @@ pg_scandir_internal(const char *dirname,
295
248
296
249
while ((direntry = readdir (dirdesc )) != NULL )
297
250
{
298
- /* Invoke the selector function to see if the direntry matches */
299
- if (!selector || (* selector ) (direntry ))
300
- {
301
- count ++ ;
251
+ count ++ ;
302
252
303
- * namelist = (struct dirent * * ) realloc ((void * ) (* namelist ),
304
- (size_t ) ((name_num + 1 ) * sizeof (struct dirent * )));
253
+ * namelist = (struct dirent * * ) realloc ((void * ) (* namelist ),
254
+ (size_t ) ((name_num + 1 ) * sizeof (struct dirent * )));
305
255
306
- if (* namelist == NULL )
307
- {
308
- closedir (dirdesc );
309
- return -1 ;
310
- }
256
+ if (* namelist == NULL )
257
+ {
258
+ closedir (dirdesc );
259
+ return -1 ;
260
+ }
311
261
312
- entrysize = sizeof (struct dirent ) - sizeof (direntry -> d_name ) +
313
- strlen (direntry -> d_name ) + 1 ;
262
+ entrysize = sizeof (struct dirent ) - sizeof (direntry -> d_name ) +
263
+ strlen (direntry -> d_name ) + 1 ;
314
264
315
- (* namelist )[name_num ] = (struct dirent * ) malloc (entrysize );
265
+ (* namelist )[name_num ] = (struct dirent * ) malloc (entrysize );
316
266
317
- if ((* namelist )[name_num ] == NULL )
318
- {
319
- closedir (dirdesc );
320
- return -1 ;
321
- }
267
+ if ((* namelist )[name_num ] == NULL )
268
+ {
269
+ closedir (dirdesc );
270
+ return -1 ;
271
+ }
322
272
323
- memcpy ((* namelist )[name_num ], direntry , entrysize );
273
+ memcpy ((* namelist )[name_num ], direntry , entrysize );
324
274
325
- name_num ++ ;
326
- }
275
+ name_num ++ ;
327
276
}
328
277
329
278
closedir (dirdesc );
330
279
331
280
return count ;
332
281
}
333
- #endif
334
282
335
283
336
284
void
0 commit comments