@@ -33,7 +33,7 @@ static intwin32_pghardlink(const char *src, const char *dst);
33
33
static int copy_dir (const char * from ,const char * to ,bool force );
34
34
#endif
35
35
36
- #if defined( sun ) || defined( WIN32 )
36
+ #ifndef HAVE_SCANDIR
37
37
static int pg_scandir_internal (migratorContext * ctx ,const char * dirname ,
38
38
struct dirent * * * namelist ,
39
39
int (* selector ) (const struct dirent * ));
@@ -235,26 +235,25 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
235
235
* pg_scandir()
236
236
*
237
237
* Wrapper for portable scandir functionality
238
- *
239
238
*/
240
239
int
241
240
pg_scandir (migratorContext * ctx ,const char * dirname ,
242
241
struct dirent * * * namelist ,
243
242
int (* selector ) (const struct dirent * ))
244
243
{
245
- #if defined( sun ) || defined( WIN32 )
244
+ #ifndef HAVE_SCANDIR
246
245
return pg_scandir_internal (ctx ,dirname ,namelist ,selector );
247
246
248
247
/*
248
+ * scandir() is originally from BSD 4.3, which had the third argument as
249
+ * non-const. Linux and other C libraries have updated it to use a const.
250
+ * http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg00214.html
251
+ *
249
252
* Here we try to guess which libc's need const, and which don't. The net
250
- * goal here is to try tosupress a compiler warning due to a prototype
253
+ * goal here is to try tosuppress a compiler warning due to a prototype
251
254
* mismatch of const usage. Ideally we would do this via autoconf, but
252
- * Postgres's autoconf doesn't test for this and it is overkill to add
253
- * autoconf just for this. scandir() is from BSD 4.3, which had the third
254
- * argument as non-const. Linux and other C libraries have updated it to
255
- * use a const.
256
- * http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg002
257
- * 14.html
255
+ * autoconf doesn't have a suitable builtin test and it seems overkill
256
+ * to add one just to avoid a warning.
258
257
*/
259
258
#elif defined(freebsd )|| defined(bsdi )|| defined(darwin )|| defined(openbsd )
260
259
/* no const */
@@ -266,19 +265,18 @@ pg_scandir(migratorContext *ctx, const char *dirname,
266
265
}
267
266
268
267
269
- #if defined( sun ) || defined( WIN32 )
268
+ #ifndef HAVE_SCANDIR
270
269
/*
271
270
* pg_scandir_internal()
272
271
*
273
- * We'll provide our own scandir function for sun, since it is not
274
- * part of the standard system library.
272
+ * Implement our own scandir() on platforms that don't have it.
275
273
*
276
274
* Returns count of files that meet the selection criteria coded in
277
275
* the function pointed to by selector. Creates an array of pointers
278
276
* to dirent structures. Address of array returned in namelist.
279
277
*
280
278
* Note that the number of dirent structures needed is dynamically
281
- * allocated using realloc. Realloc can beinneficient if invoked a
279
+ * allocated using realloc. Realloc can beinefficient if invoked a
282
280
* large number of times. Its use in pg_upgrade is to find filesystem
283
281
* filenames that have extended beyond the initial segment (file.1,
284
282
* .2, etc.) and should therefore be invoked a small number of times.