diff --git a/configure b/configure index 58fea907ea6..de9ba5af62e 100755 --- a/configure +++ b/configure @@ -18987,8 +18987,7 @@ fi - -for ac_func in cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink scandir setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l +for ac_func in cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index 5dc669f545a..5591b93e758 100644 --- a/configure.in +++ b/configure.in @@ -1193,7 +1193,7 @@ PGAC_VAR_INT_TIMEZONE AC_FUNC_ACCEPT_ARGTYPES PGAC_FUNC_GETTIMEOFDAY_1ARG -AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink scandir setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l]) +AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l]) AC_REPLACE_FUNCS(fseeko) case $host_os in diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c index b414769917f..0ea269f2599 100644 --- a/contrib/pg_upgrade/file.c +++ b/contrib/pg_upgrade/file.c @@ -21,12 +21,6 @@ static int copy_file(const char *fromfile, const char *tofile, bool force); static int win32_pghardlink(const char *src, const char *dst); #endif -#ifndef HAVE_SCANDIR -static int pg_scandir_internal(const char *dirname, - struct dirent *** namelist, - int (*selector) (const struct dirent *)); -#endif - /* * copyAndUpdateFile() @@ -228,45 +222,7 @@ copy_file(const char *srcfile, const char *dstfile, bool force) /* - * pg_scandir() - * - * Wrapper for portable scandir functionality - */ -int -pg_scandir(const char *dirname, - struct dirent *** namelist, - int (*selector) (const struct dirent *)) -{ -#ifndef HAVE_SCANDIR - return pg_scandir_internal(dirname, namelist, selector); - - /* - * scandir() is originally from BSD 4.3, which had the third argument as - * non-const. Linux and other C libraries have updated it to use a const. - * http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg002 - * 14.html - * - * Here we try to guess which libc's need const, and which don't. The net - * goal here is to try to suppress a compiler warning due to a prototype - * mismatch of const usage. Ideally we would do this via autoconf, but - * autoconf doesn't have a suitable builtin test and it seems overkill to - * add one just to avoid a warning. - */ -#elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__darwin__) || defined(__OpenBSD__) - /* no const */ - return scandir(dirname, namelist, (int (*) (struct dirent *)) selector, NULL); -#else - /* use const */ - return scandir(dirname, namelist, selector, NULL); -#endif -} - - -#ifndef HAVE_SCANDIR -/* - * pg_scandir_internal() - * - * Implement our own scandir() on platforms that don't have it. + * load_directory() * * Returns count of files that meet the selection criteria coded in * the function pointed to by selector. Creates an array of pointers @@ -274,13 +230,10 @@ pg_scandir(const char *dirname, * * Note that the number of dirent structures needed is dynamically * allocated using realloc. Realloc can be inefficient if invoked a - * large number of times. Its use in pg_upgrade is to find filesystem - * filenames that have extended beyond the initial segment (file.1, - * .2, etc.) and should therefore be invoked a small number of times. + * large number of times. */ -static int -pg_scandir_internal(const char *dirname, - struct dirent *** namelist, int (*selector) (const struct dirent *)) +int +load_directory(const char *dirname, struct dirent ***namelist) { DIR *dirdesc; struct dirent *direntry; @@ -295,42 +248,37 @@ pg_scandir_internal(const char *dirname, while ((direntry = readdir(dirdesc)) != NULL) { - /* Invoke the selector function to see if the direntry matches */ - if (!selector || (*selector) (direntry)) + count++; + + *namelist = (struct dirent **) realloc((void *) (*namelist), + (size_t) ((name_num + 1) * sizeof(struct dirent *))); + + if (*namelist == NULL) { - count++; - - *namelist = (struct dirent **) realloc((void *) (*namelist), - (size_t) ((name_num + 1) * sizeof(struct dirent *))); - - if (*namelist == NULL) - { - closedir(dirdesc); - return -1; - } - - entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) + - strlen(direntry->d_name) + 1; - - (*namelist)[name_num] = (struct dirent *) malloc(entrysize); - - if ((*namelist)[name_num] == NULL) - { - closedir(dirdesc); - return -1; - } - - memcpy((*namelist)[name_num], direntry, entrysize); - - name_num++; + closedir(dirdesc); + return -1; } + + entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) + + strlen(direntry->d_name) + 1; + + (*namelist)[name_num] = (struct dirent *) malloc(entrysize); + + if ((*namelist)[name_num] == NULL) + { + closedir(dirdesc); + return -1; + } + + memcpy((*namelist)[name_num], direntry, entrysize); + + name_num++; } closedir(dirdesc); return count; } -#endif void diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h index d64c72a5cdc..7d48e9c430b 100644 --- a/contrib/pg_upgrade/pg_upgrade.h +++ b/contrib/pg_upgrade/pg_upgrade.h @@ -333,8 +333,7 @@ const char *setupPageConverter(pageCnvCtx **result); typedef void *pageCnvCtx; #endif -int pg_scandir(const char *dirname, struct dirent *** namelist, - int (*selector) (const struct dirent *)); +int load_directory(const char *dirname, struct dirent ***namelist); const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src, const char *dst, bool force); const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src, diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c index 721bf4d8db2..74d16216f3b 100644 --- a/contrib/pg_upgrade/relfilenode.c +++ b/contrib/pg_upgrade/relfilenode.c @@ -160,7 +160,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, } snprintf(old_dir, sizeof(old_dir), "%s", maps[mapnum].old_dir); - numFiles = pg_scandir(old_dir, &namelist, NULL); + numFiles = load_directory(old_dir, &namelist); } /* Copying files might take some time, so give feedback. */