X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gnu%2Ffcntl.c;h=23b73e975c844d976a032d2582f482fac0f43f33;hb=d30babc23b4f25be970ada2e63a50220a3672281;hp=febc21363a651e47ef9ea0c99c208304ebfd35c5;hpb=1a44d77d50f4fb37c0410eed04b82303624ea2ec;p=debian%2Ftar diff --git a/gnu/fcntl.c b/gnu/fcntl.c index febc2136..23b73e97 100644 --- a/gnu/fcntl.c +++ b/gnu/fcntl.c @@ -1,8 +1,6 @@ -/* -*- buffer-read-only: t -*- vi: set ro: */ -/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Provide file descriptor control. - Copyright (C) 2009-2011 Free Software Foundation, Inc. + Copyright (C) 2009-2015 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,10 +33,13 @@ #undef fcntl #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Get declarations of the Win32 API functions. */ +/* Get declarations of the native Windows API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" + /* Upper bound on getdtablesize(). See lib/getdtablesize.c. */ # define OPEN_MAX_MAX 0x10000 @@ -88,16 +89,32 @@ 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; } - duplicated_fd = _open_osfhandle ((long) new_handle, flags); + duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags); if (duplicated_fd < 0) { CloseHandle (new_handle); - errno = EMFILE; result = -1; break; }