Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit754b90f

Browse files
committed
Fix error handling of readdir() port implementation on first file lookup
The implementation of readdir() in src/port/ which gets used by MSVC hasbeen added in399a36a, and since the beginning it considers all errorson the first file lookup as ENOENT, setting errno accordingly andletting the routine caller think that the directory is empty. Whilethis is normally enough for the case of the backend, this can confusecallers of this routine on Windows as all errors would map to the samebehavior. So, for example, even permission errors would be thought ashaving an empty directory, while there could be contents in it.This commit changes the error handling so as readdir() gets a behaviorsimilar to native implementations: force errno=0 when seeingERROR_FILE_NOT_FOUND as error and consider other errors as plainfailures.While looking at the patch, I noticed that MinGW does not enforceerrno=0 when looking at the first file, but it gets enforced on the nextfile lookups. A comment related to that was incorrect in the code.Reported-by: Yuri KurenkovDiagnosed-by: Yuri Kurenkov, Grigory SmolkinAuthor:Konstantin KnizhnikReviewed-by: Andrew Dunstan, Michael PaquierDiscussion:https://postgr.es/m/2cad7829-8d66-e39c-b937-ac825db5203d@postgrespro.ruBackpatch-through: 9.4
1 parent5bd9160 commit754b90f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎src/port/dirent.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ readdir(DIR *d)
8383
d->handle=FindFirstFile(d->dirname,&fd);
8484
if (d->handle==INVALID_HANDLE_VALUE)
8585
{
86-
errno=ENOENT;
86+
/* If there are no files, force errno=0 (unlike mingw) */
87+
if (GetLastError()==ERROR_FILE_NOT_FOUND)
88+
errno=0;
89+
else
90+
_dosmaperr(GetLastError());
8791
returnNULL;
8892
}
8993
}
9094
else
9195
{
9296
if (!FindNextFile(d->handle,&fd))
9397
{
98+
/* If there are no more files, force errno=0 (like mingw) */
9499
if (GetLastError()==ERROR_NO_MORE_FILES)
95-
{
96-
/* No more files, force errno=0 (unlike mingw) */
97100
errno=0;
98-
returnNULL;
99-
}
100-
_dosmaperr(GetLastError());
101+
else
102+
_dosmaperr(GetLastError());
101103
returnNULL;
102104
}
103105
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp