Mercurial > hg > octave-nkf > gnulib-hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
12455:dbc90a3fc4ed | 12456:f3aceada3c52 |
---|---|
153 static void | 153 static void |
154 check_flags (void) | 154 check_flags (void) |
155 { | 155 { |
156 switch (0) | 156 switch (0) |
157 { | 157 { |
158 #ifdef F_DUPFD | |
159 case F_DUPFD: | 158 case F_DUPFD: |
160 # if F_DUPFD | 159 #if F_DUPFD |
161 # endif | 160 #endif |
162 #endif | 161 |
163 | |
164 #ifdef F_DUPFD_CLOEXEC | |
165 case F_DUPFD_CLOEXEC: | 162 case F_DUPFD_CLOEXEC: |
166 # if F_DUPFD_CLOEXEC | 163 #if F_DUPFD_CLOEXEC |
167 # endif | 164 #endif |
168 #endif | 165 |
169 | |
170 #ifdef F_GETFD | |
171 case F_GETFD: | 166 case F_GETFD: |
172 # if F_GETFD | 167 #if F_GETFD |
173 # endif | |
174 #endif | 168 #endif |
175 | 169 |
176 #ifdef F_SETFD | 170 #ifdef F_SETFD |
177 case F_SETFD: | 171 case F_SETFD: |
178 # if F_SETFD | 172 # if F_SETFD |
238 { | 232 { |
239 struct dummy_struct s = { 0L, 4 }; | 233 struct dummy_struct s = { 0L, 4 }; |
240 ASSERT (func2 (4, &s) == 4); | 234 ASSERT (func2 (4, &s) == 4); |
241 } | 235 } |
242 check_flags (); | 236 check_flags (); |
243 | |
244 #if HAVE_FCNTL | |
245 | 237 |
246 /* Assume std descriptors were provided by invoker, and ignore fds | 238 /* Assume std descriptors were provided by invoker, and ignore fds |
247 that might have been inherited. */ | 239 that might have been inherited. */ |
248 fd = creat (file, 0600); | 240 fd = creat (file, 0600); |
249 ASSERT (STDERR_FILENO < fd); | 241 ASSERT (STDERR_FILENO < fd); |
333 ASSERT (!is_inheritable (fd + 2)); | 325 ASSERT (!is_inheritable (fd + 2)); |
334 ASSERT (is_mode (fd, O_TEXT)); | 326 ASSERT (is_mode (fd, O_TEXT)); |
335 ASSERT (is_mode (fd + 2, O_TEXT)); | 327 ASSERT (is_mode (fd + 2, O_TEXT)); |
336 ASSERT (close (fd + 2) == 0); | 328 ASSERT (close (fd + 2) == 0); |
337 | 329 |
330 /* Test F_GETFD. */ | |
331 errno = 0; | |
332 ASSERT (fcntl (-1, F_GETFD) == -1); | |
333 ASSERT (errno == EBADF); | |
334 errno = 0; | |
335 ASSERT (fcntl (fd + 1, F_GETFD) == -1); | |
336 ASSERT (errno == EBADF); | |
337 errno = 0; | |
338 ASSERT (fcntl (10000000, F_GETFD) == -1); | |
339 ASSERT (errno == EBADF); | |
340 { | |
341 int result = fcntl (fd, F_GETFD); | |
342 ASSERT (0 <= result); | |
343 ASSERT ((result & FD_CLOEXEC) == FD_CLOEXEC); | |
344 ASSERT (dup (fd) == fd + 1); | |
345 result = fcntl (fd + 1, F_GETFD); | |
346 ASSERT (0 <= result); | |
347 ASSERT ((result & FD_CLOEXEC) == 0); | |
348 ASSERT (close (fd + 1) == 0); | |
349 } | |
350 | |
338 /* Cleanup. */ | 351 /* Cleanup. */ |
339 ASSERT (close (fd) == 0); | 352 ASSERT (close (fd) == 0); |
340 ASSERT (unlink (file) == 0); | 353 ASSERT (unlink (file) == 0); |
341 | 354 |
342 #endif /* HAVE_FCNTL */ | |
343 | |
344 return 0; | 355 return 0; |
345 } | 356 } |