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 if (write(fd, buf, strlen(buf)) != strlen(buf))
26 ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
28 p = failtest_malloc(100, __FILE__, __LINE__);
30 /* We are the child. Do a heap of writes. */
33 for (i = 0; i < strlen(buf)+1; i++)
34 if (failtest_write(fd, "x", 1, __FILE__, __LINE__)
37 failtest_close(fd, __FILE__, __LINE__);
41 /* Seek pointer should be left alone! */
42 ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
43 /* Length should be restored. */
44 ok1(lseek(fd, 0, SEEK_END) == strlen(buf));
45 lseek(fd, 0, SEEK_SET);
46 ok1(read(fd, buf, strlen(buf)) == strlen("Hello world!"));
47 ok1(strcmp(buf, "Hello world!") == 0);
48 failtest_close(fd, __FILE__, __LINE__);