aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/fd.c6
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c63
-rw-r--r--src/port/dirent.c8
-rw-r--r--src/port/dirmod.c22
-rw-r--r--src/port/pgcheckdir.c14
5 files changed, 56 insertions, 57 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index ca12b9af77c..a3211b1f041 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1687,11 +1687,7 @@ ReadDir(DIR *dir, const char *dirname)
return dent;
#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
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 54cc5b03024..5ea51a02ef5 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -742,8 +742,7 @@ FindEndOfXLOG(void)
exit(1);
}
- errno = 0;
- while ((xlde = readdir(xldir)) != NULL)
+ while (errno = 0, (xlde = readdir(xldir)) != NULL)
{
if (strlen(xlde->d_name) == 24 &&
strspn(xlde->d_name, "0123456789ABCDEF") == 24)
@@ -767,25 +766,27 @@ FindEndOfXLOG(void)
newXlogSeg = seg;
}
}
- 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)
{
- fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
+ fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
+ progname, XLOGDIR, strerror(errno));
+ exit(1);
+ }
+
+ if (closedir(xldir))
+ {
+ fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
progname, XLOGDIR, strerror(errno));
exit(1);
}
- closedir(xldir);
/*
* Finally, convert to new xlog seg size, and advance by one to ensure we
@@ -817,8 +818,7 @@ KillExistingXLOG(void)
exit(1);
}
- errno = 0;
- while ((xlde = readdir(xldir)) != NULL)
+ while (errno = 0, (xlde = readdir(xldir)) != NULL)
{
if (strlen(xlde->d_name) == 24 &&
strspn(xlde->d_name, "0123456789ABCDEF") == 24)
@@ -831,25 +831,27 @@ KillExistingXLOG(void)
exit(1);
}
}
- 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)
{
- fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
+ fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
+ progname, XLOGDIR, strerror(errno));
+ exit(1);
+ }
+
+ if (closedir(xldir))
+ {
+ fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
progname, XLOGDIR, strerror(errno));
exit(1);
}
- closedir(xldir);
}
@@ -873,8 +875,7 @@ KillExistingArchiveStatus(void)
exit(1);
}
- errno = 0;
- while ((xlde = readdir(xldir)) != NULL)
+ while (errno = 0, (xlde = readdir(xldir)) != NULL)
{
if (strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
(strcmp(xlde->d_name + 24, ".ready") == 0 ||
@@ -888,25 +889,27 @@ KillExistingArchiveStatus(void)
exit(1);
}
}
- 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)
{
- fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
+ fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
+ progname, ARCHSTATDIR, strerror(errno));
+ exit(1);
+ }
+
+ if (closedir(xldir))
+ {
+ fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
progname, ARCHSTATDIR, strerror(errno));
exit(1);
}
- closedir(xldir);
}
diff --git a/src/port/dirent.c b/src/port/dirent.c
index 6219ccb4694..9631eeee46b 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/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;
}
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;