6 #include <ccan/tap/tap.h>
7 /* Include the C files directly. */
8 #include <ccan/failtest/failtest.c>
10 int main(int argc, char *argv[])
14 char buf[] = "Hello world!";
17 failtest_init(argc, argv);
19 fd = failtest_open("run-write-scratchpad", __FILE__, __LINE__,
20 O_RDWR|O_CREAT, 0600);
21 /* Child will fail, ignore. */
24 write(fd, buf, strlen(buf));
25 ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
27 p = failtest_malloc(100, __FILE__, __LINE__);
29 /* We are the child. Do a heap of writes. */
32 for (i = 0; i < strlen(buf)+1; i++)
33 if (failtest_write(fd, "x", 1, __FILE__, __LINE__)
36 failtest_close(fd, __FILE__, __LINE__);
40 /* Seek pointer should be left alone! */
41 ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
42 /* Length should be restored. */
43 ok1(lseek(fd, 0, SEEK_END) == strlen(buf));
44 lseek(fd, 0, SEEK_SET);
45 ok1(read(fd, buf, strlen(buf)) == strlen("Hello world!"));
46 ok1(strcmp(buf, "Hello world!") == 0);
47 failtest_close(fd, __FILE__, __LINE__);