X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Ffcntl.c;fp=lib%2Ffcntl.c;h=3dfb6b73a87ee7cfba937ab746d4923fb4818205;hb=dc84183747ce1703eb99685b5dbde1f65a143c06;hp=c51e8ded56c13d102fcd9c9996a0f1a2a8e2438c;hpb=a2016c1de6e4884f6c8ed5cc498f3bf821c25ca4;p=debian%2Fgzip diff --git a/lib/fcntl.c b/lib/fcntl.c index c51e8de..3dfb6b7 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -1,6 +1,6 @@ /* Provide file descriptor control. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009-2012 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 @@ -33,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 @@ -91,7 +94,7 @@ dupfd (int oldfd, int newfd, int flags) 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); @@ -187,7 +190,21 @@ rpl_fcntl (int fd, int action, /* arg */...) errno = EINVAL; else { + /* Haiku alpha 2 loses fd flags on original. */ + int flags = fcntl (fd, F_GETFD); + if (flags < 0) + { + result = -1; + break; + } result = fcntl (fd, action, target); + if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) + { + int saved_errno = errno; + close (result); + result = -1; + errno = saved_errno; + } # if REPLACE_FCHDIR if (0 <= result) result = _gl_register_dup (fd, result);