summaryrefslogtreecommitdiff
path: root/lib/fcntl.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fcntl.c')
-rw-r--r--lib/fcntl.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 54f748606b7..1e35dd1a4f9 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -89,8 +89,25 @@ dupfd (int oldfd, int newfd, int flags)
inherit, /* InheritHandle */
DUPLICATE_SAME_ACCESS)) /* Options */
{
- /* TODO: Translate GetLastError () into errno. */
- errno = EMFILE;
+ switch (GetLastError ())
+ {
+ case ERROR_TOO_MANY_OPEN_FILES:
+ errno = EMFILE;
+ break;
+ case ERROR_INVALID_HANDLE:
+ case ERROR_INVALID_TARGET_HANDLE:
+ case ERROR_DIRECT_ACCESS_HANDLE:
+ errno = EBADF;
+ break;
+ case ERROR_INVALID_PARAMETER:
+ case ERROR_INVALID_FUNCTION:
+ case ERROR_INVALID_ACCESS:
+ errno = EINVAL;
+ break;
+ default:
+ errno = EACCES;
+ break;
+ }
result = -1;
break;
}
@@ -98,7 +115,6 @@ dupfd (int oldfd, int newfd, int flags)
if (duplicated_fd < 0)
{
CloseHandle (new_handle);
- errno = EMFILE;
result = -1;
break;
}