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>
+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.
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Native Woe32 API. */
+# include <sys/ioctl.h>
# include <sys/socket.h>
# include <unistd.h>
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. */
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. */
else
{
/* Win32 does not support non-blocking on regular files. */
+ if (!value)
+ return 0;
errno = ENOTSUP;
return -1;
}
Depends-on:
close
-open
pipe-posix
socket
/* 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);