projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
prepare NEWS.stable
[gnulib.git]
/
tests
/
test-fchdir.c
diff --git
a/tests/test-fchdir.c
b/tests/test-fchdir.c
index
75819eb
..
b66667f
100644
(file)
--- a/
tests/test-fchdir.c
+++ b/
tests/test-fchdir.c
@@
-1,5
+1,5
@@
/* Test changing to a directory named by a file descriptor.
/* Test changing to a directory named by a file descriptor.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009
-2012
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-20,37
+20,43
@@
#include <unistd.h>
#include <unistd.h>
+#include "signature.h"
+SIGNATURE_CHECK (fchdir, int, (int));
+
#include <errno.h>
#include <fcntl.h>
#include <errno.h>
#include <fcntl.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cloexec.h"
#include <stdlib.h>
#include <string.h>
#include "cloexec.h"
-
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
int
main (void)
{
int
main (void)
{
- char *cwd
= getcwd (NULL, 0)
;
- int fd
= open (".", O_RDONLY)
;
+ char *cwd;
+ int fd;
int i;
int i;
+ cwd = getcwd (NULL, 0);
ASSERT (cwd);
ASSERT (cwd);
+
+ fd = open (".", O_RDONLY);
ASSERT (0 <= fd);
ASSERT (0 <= fd);
- /* Check for failure cases. */
+ /* Test behaviour for invalid file descriptors. */
+ {
+ errno = 0;
+ ASSERT (fchdir (-1) == -1);
+ ASSERT (errno == EBADF);
+ }
+ {
+ errno = 0;
+ ASSERT (fchdir (99) == -1);
+ ASSERT (errno == EBADF);
+ }
+
+ /* Check for other failure cases. */
{
int bad_fd = open ("/dev/null", O_RDONLY);
ASSERT (0 <= bad_fd);
{
int bad_fd = open ("/dev/null", O_RDONLY);
ASSERT (0 <= bad_fd);
@@
-58,9
+64,6
@@
main (void)
ASSERT (fchdir (bad_fd) == -1);
ASSERT (errno == ENOTDIR);
ASSERT (close (bad_fd) == 0);
ASSERT (fchdir (bad_fd) == -1);
ASSERT (errno == ENOTDIR);
ASSERT (close (bad_fd) == 0);
- errno = 0;
- ASSERT (fchdir (-1) == -1);
- ASSERT (errno == EBADF);
}
/* Repeat test twice, once in '.' and once in '..'. */
}
/* Repeat test twice, once in '.' and once in '..'. */
@@
-93,7
+96,7
@@
main (void)
ASSERT (close (fd) == 0);
ASSERT (fcntl (new_fd, F_DUPFD, fd) == fd);
ASSERT (close (new_fd) == 0);
ASSERT (close (fd) == 0);
ASSERT (fcntl (new_fd, F_DUPFD, fd) == fd);
ASSERT (close (new_fd) == 0);
-#if GNULIB_DUP3
+#if GNULIB_
TEST_
DUP3
ASSERT (dup3 (fd, new_fd, 0) == new_fd);
ASSERT (dup3 (new_fd, fd, 0) == fd);
ASSERT (close (new_fd) == 0);
ASSERT (dup3 (fd, new_fd, 0) == new_fd);
ASSERT (dup3 (new_fd, fd, 0) == fd);
ASSERT (close (new_fd) == 0);