aboutsummaryrefslogtreecommitdiff
path: root/src/port/dirmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/dirmod.c')
-rw-r--r--src/port/dirmod.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 17fd96573db..f61d68b301a 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -448,8 +448,7 @@ pgfnames(const char *path)
filenames = (char **) palloc(fnsize * sizeof(char *));
- errno = 0;
- while ((file = readdir(dir)) != NULL)
+ while (errno = 0, (file = readdir(dir)) != NULL)
{
if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
{
@@ -461,17 +460,14 @@ pgfnames(const char *path)
}
filenames[numnames++] = pstrdup(file->d_name);
}
- errno = 0;
}
-#ifdef WIN32
- /*
- * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
- * released version
- */
+#ifdef WIN32
+ /* Bug in old Mingw dirent.c; fixed in mingw-runtime-3.2, 2003-10-10 */
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = 0;
#endif
+
if (errno)
{
#ifndef FRONTEND
@@ -484,7 +480,15 @@ pgfnames(const char *path)
filenames[numnames] = NULL;
- closedir(dir);
+ if (closedir(dir))
+ {
+#ifndef FRONTEND
+ elog(WARNING, "could not close directory \"%s\": %m", path);
+#else
+ fprintf(stderr, _("could not close directory \"%s\": %s\n"),
+ path, strerror(errno));
+#endif
+ }
return filenames;
}