Mercurial > hg > octave-kai > gnulib-hg
changeset 14516:8b5a7d072ac7
nonblocking: fix mingw test failures
Actually testing on mingw uncovered a few more problems.
* lib/nonblocking.c (set_nonblocking_flag): Succeed when clearing
non-blocking flag on regular file.
(get_nonblocking_flag): Set errno on invalid fd.
* tests/test-nonblocking.c (main): Avoid test failure on
directories if fchdir is not active.
* modules/nonblocking-tests (Depends-on): Drop unused dependency.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Thu, 31 Mar 2011 15:28:37 -0600 |
parents | b2069b8212d0 |
children | 8636d98120a9 f117125e8cb9 |
files | ChangeLog lib/nonblocking.c modules/nonblocking-tests tests/test-nonblocking.c |
diffstat | 4 files changed, 31 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-03-31 Eric Blake <eblake@redhat.com> + + nonblocking: fix mingw test failures + * lib/nonblocking.c (set_nonblocking_flag): Succeed when clearing + non-blocking flag on regular file. + (get_nonblocking_flag): Set errno on invalid fd. + * tests/test-nonblocking.c (main): Avoid test failure on + directories if fchdir is not active. + * modules/nonblocking-tests (Depends-on): Drop unused dependency. + 2011-03-31 Bruno Haible <bruno@clisp.org> Fix bug with gl_WARN_ON_USE_PREPARE, introduced on 2011-01-23.
--- a/lib/nonblocking.c +++ b/lib/nonblocking.c @@ -24,6 +24,7 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* Native Woe32 API. */ +# include <sys/ioctl.h> # include <sys/socket.h> # include <unistd.h> @@ -35,6 +36,11 @@ 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. */ @@ -56,6 +62,11 @@ 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. */ @@ -90,6 +101,8 @@ else { /* Win32 does not support non-blocking on regular files. */ + if (!value) + return 0; errno = ENOTSUP; return -1; }
--- a/modules/nonblocking-tests +++ b/modules/nonblocking-tests @@ -4,7 +4,6 @@ Depends-on: close -open pipe-posix socket
--- a/tests/test-nonblocking.c +++ b/tests/test-nonblocking.c @@ -55,11 +55,14 @@ /* Test directories; setting nonblocking is unspecified. */ fd_file = open (".", O_RDONLY); - ASSERT (STDERR_FILENO < fd_file); - ASSERT (get_nonblocking_flag (fd_file) == 0); - ASSERT (set_nonblocking_flag (fd_file, false) == 0); - ASSERT (get_nonblocking_flag (fd_file) == 0); - ASSERT (close (fd_file) == 0); + if (STDERR_FILENO < fd_file) + { + /* mingw can't open directories unless fchdir module is active. */ + ASSERT (get_nonblocking_flag (fd_file) == 0); + ASSERT (set_nonblocking_flag (fd_file, false) == 0); + ASSERT (get_nonblocking_flag (fd_file) == 0); + ASSERT (close (fd_file) == 0); + } /* Test pipes. */ ASSERT (pipe (fd_pipe) == 0);