X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fnonblocking.c;h=95d77362d4bf2b0506f7581659d9d95ea470c93c;hb=a828bb24ee96386201c4236ea917677b6c536c7d;hp=cb103be4becb7e02b32964a28269bc3c47a3d2eb;hpb=111a4bf8dd3d9646133305c19964d8080e0b7085;p=gnulib.git diff --git a/lib/nonblocking.c b/lib/nonblocking.c index cb103be4b..95d77362d 100644 --- a/lib/nonblocking.c +++ b/lib/nonblocking.c @@ -1,5 +1,5 @@ /* Non-blocking I/O for pipe or socket descriptors. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011-2013 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 @@ -22,19 +22,27 @@ #include #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Native Woe32 API. */ +/* Native Windows API. */ +# include # include # include -/* Get declarations of the Win32 API functions. */ +/* Get declarations of the native Windows API functions. */ # define WIN32_LEAN_AND_MEAN # include +# include "msvc-nothrow.h" + int get_nonblocking_flag (int desc) { HANDLE h = (HANDLE) _get_osfhandle (desc); + if (h == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return -1; + } if (GetFileType (h) == FILE_TYPE_PIPE) { /* h is a pipe or socket. */ @@ -48,7 +56,8 @@ get_nonblocking_flag (int desc) return -1; } else - /* Win32 does not support non-blocking on regular files. */ + /* The native Windows API does not support non-blocking on regular + files. */ return 0; } @@ -56,6 +65,11 @@ int set_nonblocking_flag (int desc, bool value) { HANDLE h = (HANDLE) _get_osfhandle (desc); + if (h == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return -1; + } if (GetFileType (h) == FILE_TYPE_PIPE) { /* h is a pipe or socket. */ @@ -89,7 +103,10 @@ set_nonblocking_flag (int desc, bool value) } else { - /* Win32 does not support non-blocking on regular files. */ + /* The native Windows API does not support non-blocking on regular + files. */ + if (!value) + return 0; errno = ENOTSUP; return -1; } @@ -100,7 +117,7 @@ set_nonblocking_flag (int desc, bool value) # include -# if !O_NONBLOCK +# if GNULIB_defined_O_NONBLOCK # error Please port nonblocking to your platform # endif