Mercurial > hg > octave-nkf > gnulib-hg
diff tests/test-fcntl.c @ 12456:f3aceada3c52
fcntl: port portions of fcntl to mingw
Borrow ideas from dup_cloexec and dup3 to implement F_DUPFD and
F_DUPFD_CLOEXEC. Support querying the inheritance status via
F_GETFD, but for now, no support for changing with F_SETFD.
The remaining portions of fcntl fail with EINVAL.
* m4/fcntl.m4 (gl_FUNC_FCNTL): Also build fcntl.c on mingw.
* lib/fcntl.c (fcntl) <F_DUPFD, F_DUPFD_CLOEXEC, F_GETFD>: Provide
replacement for mingw.
* modules/fcntl (Description): Update.
(Depends-on): Add dup2.
* m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): Add witness.
* modules/fcntl-h (Makefile.am): Substitute it.
* lib/fcntl.in.h (fcntl): Update declaration.
(F_DUPFD, F_GETFD): New macros, when needed.
* doc/posix-headers/fcntl.texi (fcntl.h): Update documentation.
* doc/posix-functions/fcntl.texi (fcntl): Likewise.
* tests/test-fcntl.c (check_flags, main): Enhance test for items
we now guarantee.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Wed, 16 Dec 2009 09:11:32 -0700 |
parents | f7624052e60d |
children | f5dcba492f50 |
line wrap: on
line diff
--- a/tests/test-fcntl.c +++ b/tests/test-fcntl.c @@ -155,22 +155,16 @@ { switch (0) { -#ifdef F_DUPFD case F_DUPFD: -# if F_DUPFD -# endif +#if F_DUPFD #endif -#ifdef F_DUPFD_CLOEXEC case F_DUPFD_CLOEXEC: -# if F_DUPFD_CLOEXEC -# endif +#if F_DUPFD_CLOEXEC #endif -#ifdef F_GETFD case F_GETFD: -# if F_GETFD -# endif +#if F_GETFD #endif #ifdef F_SETFD @@ -241,8 +235,6 @@ } check_flags (); -#if HAVE_FCNTL - /* Assume std descriptors were provided by invoker, and ignore fds that might have been inherited. */ fd = creat (file, 0600); @@ -335,11 +327,30 @@ ASSERT (is_mode (fd + 2, O_TEXT)); ASSERT (close (fd + 2) == 0); + /* Test F_GETFD. */ + errno = 0; + ASSERT (fcntl (-1, F_GETFD) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_GETFD) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_GETFD) == -1); + ASSERT (errno == EBADF); + { + int result = fcntl (fd, F_GETFD); + ASSERT (0 <= result); + ASSERT ((result & FD_CLOEXEC) == FD_CLOEXEC); + ASSERT (dup (fd) == fd + 1); + result = fcntl (fd + 1, F_GETFD); + ASSERT (0 <= result); + ASSERT ((result & FD_CLOEXEC) == 0); + ASSERT (close (fd + 1) == 0); + } + /* Cleanup. */ ASSERT (close (fd) == 0); ASSERT (unlink (file) == 0); -#endif /* HAVE_FCNTL */ - return 0; }