@@ -21,12 +21,6 @@ static int copy_file(const char *fromfile, const char *tofile, bool force);
2121static int win32_pghardlink (const char * src , const char * dst );
2222#endif
2323
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-
3024
3125/*
3226 * copyAndUpdateFile()
@@ -228,59 +222,18 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
228222
229223
230224/*
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()
270226 *
271227 * Returns count of files that meet the selection criteria coded in
272228 * the function pointed to by selector. Creates an array of pointers
273229 * to dirent structures. Address of array returned in namelist.
274230 *
275231 * Note that the number of dirent structures needed is dynamically
276232 * 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.
280234 */
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 )
284237{
285238 DIR * dirdesc ;
286239 struct dirent * direntry ;
@@ -295,42 +248,37 @@ pg_scandir_internal(const char *dirname,
295248
296249 while ((direntry = readdir (dirdesc )) != NULL )
297250 {
298- /* Invoke the selector function to see if the direntry matches */
299- if (!selector || (* selector ) (direntry ))
300- {
301- count ++ ;
251+ count ++ ;
302252
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 * )));
305255
306- if (* namelist == NULL )
307- {
308- closedir (dirdesc );
309- return -1 ;
310- }
256+ if (* namelist == NULL )
257+ {
258+ closedir (dirdesc );
259+ return -1 ;
260+ }
311261
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 ;
314264
315- (* namelist )[name_num ] = (struct dirent * ) malloc (entrysize );
265+ (* namelist )[name_num ] = (struct dirent * ) malloc (entrysize );
316266
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+ }
322272
323- memcpy ((* namelist )[name_num ], direntry , entrysize );
273+ memcpy ((* namelist )[name_num ], direntry , entrysize );
324274
325- name_num ++ ;
326- }
275+ name_num ++ ;
327276 }
328277
329278 closedir (dirdesc );
330279
331280 return count ;
332281}
333- #endif
334282
335283
336284void
0 commit comments