From dec3475763be252103922a887920012eeb32dc26 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 31 Mar 2011 15:28:37 -0600 Subject: [PATCH] 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 --- ChangeLog | 10 ++++++++++ lib/nonblocking.c | 13 +++++++++++++ modules/nonblocking-tests | 1 - tests/test-nonblocking.c | 13 ++++++++----- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c4687ce05..9f5847191 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-03-31 Eric Blake + + 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 Fix bug with gl_WARN_ON_USE_PREPARE, introduced on 2011-01-23. diff --git a/lib/nonblocking.c b/lib/nonblocking.c index cb103be4b..f28e4231b 100644 --- a/lib/nonblocking.c +++ b/lib/nonblocking.c @@ -24,6 +24,7 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* Native Woe32 API. */ +# include # include # include @@ -35,6 +36,11 @@ 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. */ @@ -56,6 +62,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. */ @@ -90,6 +101,8 @@ set_nonblocking_flag (int desc, bool value) else { /* Win32 does not support non-blocking on regular files. */ + if (!value) + return 0; errno = ENOTSUP; return -1; } diff --git a/modules/nonblocking-tests b/modules/nonblocking-tests index 94fccb208..34d206d77 100644 --- a/modules/nonblocking-tests +++ b/modules/nonblocking-tests @@ -4,7 +4,6 @@ tests/macros.h Depends-on: close -open pipe-posix socket diff --git a/tests/test-nonblocking.c b/tests/test-nonblocking.c index 0762cd0ae..f1b761054 100644 --- a/tests/test-nonblocking.c +++ b/tests/test-nonblocking.c @@ -55,11 +55,14 @@ main (void) /* 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); -- 2.11.0