+2011-09-16 Eric Blake <eblake@redhat.com>
+
+ test-fsync: yet another enhancement
+ * tests/test-fsync.c (main): Also test behavior on read-only text
+ file.
+
2011-09-16 Bruno Haible <bruno@clisp.org>
Enhance fsync, fdatasync tests.
int fd;
const char *file = "test-fsync.txt";
+ /* Assuming stdin and stdout are ttys, fsync is allowed to fail, but
+ may succeed as an extension. */
for (fd = 0; fd < 2; fd++)
if (fsync (fd) != 0)
{
);
}
+ /* fsync must fail on invalid fd. */
errno = 0;
ASSERT (fsync (-1) == -1);
ASSERT (errno == EBADF);
ASSERT (write (fd, "hello", 5) == 5);
ASSERT (fsync (fd) == 0);
ASSERT (close (fd) == 0);
+
+ /* For a read-only regular file input file descriptor, fsync should
+ succeed (since at least atime changes can be synchronized). */
+ fd = open (file, O_RDONLY);
+ ASSERT (0 <= fd);
+ {
+ char buf[1];
+ ASSERT (read (fd, buf, sizeof buf) == sizeof buf);
+ }
+ ASSERT (fsync (fd) == 0);
+ ASSERT (close (fd) == 0);
+
ASSERT (unlink (file) == 0);
return 0;