aboutsummaryrefslogtreecommitdiff
path: root/src/port/pgcheckdir.c
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
commitd73cc5857faca215ee95c858e836bcc12d1d1b70 (patch)
treedc498d422c12b1bf297098b7728d86d9025fbd78 /src/port/pgcheckdir.c
parent697becf743b3176a038d78857b14976d441a0027 (diff)
downloadpostgresql-d73cc5857faca215ee95c858e836bcc12d1d1b70.tar.gz
postgresql-d73cc5857faca215ee95c858e836bcc12d1d1b70.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/pgcheckdir.c')
-rw-r--r--src/port/pgcheckdir.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/port/pgcheckdir.c b/src/port/pgcheckdir.c
index 9453bcb68a6..3a2a34cbc61 100644
--- a/src/port/pgcheckdir.c
+++ b/src/port/pgcheckdir.c
@@ -32,14 +32,12 @@ pg_check_dir(const char *dir)
DIR *chkdir;
struct dirent *file;
- 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)
@@ -55,18 +53,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? */
return result;