aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2011-11-17 21:59:04 -0500
committerBruce Momjian <bruce@momjian.us>2011-11-17 21:59:49 -0500
commit7012b5edb7f12be9f9d2816bb64fcb80515cc18c (patch)
tree6cf5ecf4711ed588752a6ea353c2ae6e75a16dc9
parentfc6d1006bda783cc002c61a5f072905849dbde4b (diff)
downloadpostgresql-7012b5edb7f12be9f9d2816bb64fcb80515cc18c.tar.gz
postgresql-7012b5edb7f12be9f9d2816bb64fcb80515cc18c.zip
Remove scandir() requirement in pg_upgrade; instead just use readdir()
--- we were not using the scandir pattern filtering anyway. This also removes the scandir requirement in configure.
-rwxr-xr-xconfigure3
-rw-r--r--configure.in2
-rw-r--r--contrib/pg_upgrade/file.c96
-rw-r--r--contrib/pg_upgrade/pg_upgrade.h3
-rw-r--r--contrib/pg_upgrade/relfilenode.c2
5 files changed, 26 insertions, 80 deletions
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++;
+ count++;
- *namelist = (struct dirent **) realloc((void *) (*namelist),
- (size_t) ((name_num + 1) * sizeof(struct dirent *)));
+ *namelist = (struct dirent **) realloc((void *) (*namelist),
+ (size_t) ((name_num + 1) * sizeof(struct dirent *)));
- if (*namelist == NULL)
- {
- closedir(dirdesc);
- return -1;
- }
+ if (*namelist == NULL)
+ {
+ closedir(dirdesc);
+ return -1;
+ }
- entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
- strlen(direntry->d_name) + 1;
+ entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
+ strlen(direntry->d_name) + 1;
- (*namelist)[name_num] = (struct dirent *) malloc(entrysize);
+ (*namelist)[name_num] = (struct dirent *) malloc(entrysize);
- if ((*namelist)[name_num] == NULL)
- {
- closedir(dirdesc);
- return -1;
- }
+ if ((*namelist)[name_num] == NULL)
+ {
+ closedir(dirdesc);
+ return -1;
+ }
- memcpy((*namelist)[name_num], direntry, entrysize);
+ memcpy((*namelist)[name_num], direntry, entrysize);
- name_num++;
- }
+ 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. */