mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
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.
This commit is contained in:
@ -50,8 +50,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)
|
||||
{
|
||||
@ -63,14 +62,10 @@ 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
|
||||
*/
|
||||
/* Bug in old Mingw dirent.c; fixed in mingw-runtime-3.2, 2003-10-10 */
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
errno = 0;
|
||||
#endif
|
||||
@ -87,7 +82,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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user