Eric Blake wrote: > > - if (fsync (0) != 0) > + if (fsync (STDOUT_FILENO) != 0) > { > ASSERT (errno == EINVAL /* POSIX */ > || errno == ENOTSUP /* seen on MacOS X 10.5 */ > || errno == EBADF /* seen on AIX 7.1 */ > - ); > + ); > }
The original intent of that code was to test the behaviour of fsync on a read-only file descriptor, and STDIN_FILENO is one. Why should it be better to test STDOUT_FILENO? Why not test both? Like this proposed patch. (Which also add blank lines as separators, to make the test more readable.) --- tests/test-fsync.c.orig Fri Sep 16 22:35:05 2011 +++ tests/test-fsync.c Fri Sep 16 22:34:09 2011 @@ -32,16 +32,19 @@ int fd; const char *file = "test-fsync.txt"; - if (fsync (STDOUT_FILENO) != 0) - { - ASSERT (errno == EINVAL /* POSIX */ - || errno == ENOTSUP /* seen on MacOS X 10.5 */ - || errno == EBADF /* seen on AIX 7.1 */ - ); - } + for (fd = 0; fd < 2; fd++) + if (fsync (fd) != 0) + { + ASSERT (errno == EINVAL /* POSIX */ + || errno == ENOTSUP /* seen on MacOS X 10.5 */ + || errno == EBADF /* seen on AIX 7.1 */ + ); + } + errno = 0; ASSERT (fsync (-1) == -1); ASSERT (errno == EBADF); + fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644); ASSERT (0 <= fd); ASSERT (write (fd, "hello", 5) == 5); -- In memoriam Georgiy Gongadze <http://en.wikipedia.org/wiki/Georgiy_Gongadze>