aboutsummaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-03-21 13:45:11 -0400
committerBruce Momjian <bruce@momjian.us>2014-03-21 13:45:11 -0400
commit6f03927fce038096f53ca67eeab9adb24938f8a6 (patch)
treee6ebc4031e1ec37c0766e1ae6baa83f39b0da227 /src/port
parent68a2e52bbaf98f136a96b3a0d734ca52ca440a95 (diff)
downloadpostgresql-6f03927fce038096f53ca67eeab9adb24938f8a6.tar.gz
postgresql-6f03927fce038096f53ca67eeab9adb24938f8a6.zip
Properly check for readdir/closedir() failures
Clear errno before calling readdir() and handle old MinGW errno bug while adding full test coverage for readdir/closedir failures. Backpatch through 8.4.
Diffstat (limited to 'src/port')
-rw-r--r--src/port/dirent.c8
-rw-r--r--src/port/pgcheckdir.c14
2 files changed, 9 insertions, 13 deletions
diff --git a/src/port/dirent.c b/src/port/dirent.c
index f9d93ea7d86..3bdc03e9b44 100644
--- a/src/port/dirent.c
+++ b/src/port/dirent.c
@@ -105,15 +105,19 @@ readdir(DIR *d)
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH
* long */
d->ret.d_namlen = strlen(d->ret.d_name);
+
return &d->ret;
}
int
closedir(DIR *d)
{
+ int ret = 0;
+
if (d->handle != INVALID_HANDLE_VALUE)
- FindClose(d->handle);
+ ret = !FindClose(d->handle);
free(d->dirname);
free(d);
- return 0;
+
+ return ret;
}
diff --git a/src/port/pgcheckdir.c b/src/port/pgcheckdir.c
index fc97f8cc1da..502d4f377d9 100644
--- a/src/port/pgcheckdir.c
+++ b/src/port/pgcheckdir.c
@@ -33,14 +33,11 @@ pg_check_dir(const char *dir)
struct dirent *file;
bool dot_found = false;
- errno = 0;
-
chkdir = opendir(dir);
-
if (chkdir == NULL)
return (errno == ENOENT) ? 0 : -1;
- while ((file = readdir(chkdir)) != NULL)
+ while (errno = 0, (file = readdir(chkdir)) != NULL)
{
if (strcmp(".", file->d_name) == 0 ||
strcmp("..", file->d_name) == 0)
@@ -68,17 +65,12 @@ pg_check_dir(const char *dir)
}
#ifdef WIN32
- /*
- * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
- * released version
- */
+ /* Bug in old Mingw dirent.c; fixed in mingw-runtime-3.2, 2003-10-10 */
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = 0;
#endif
- closedir(chkdir);
-
- if (errno != 0)
+ if (errno || closedir(chkdir))
result = -1; /* some kind of I/O error? */
/* We report on dot-files if we _only_ find dot files */