5 static const char fn
[] = "/tmp/write-test.txt";
6 static const char str
[] = "Test write() append\n";
7 static size_t len
= sizeof(str
) - 1;
15 if ((fd
= open(fn
, O_CREAT
| O_RDWR
, 0600)) == -1)
16 err(1, "Cannot open `%s'", fn
);
17 if (write(fd
, str
, len
) != (ssize_t
)len
)
18 err(1, "Write failed");
20 err(1, "Close failed");
21 if ((fd
= open(fn
, O_WRONLY
| O_APPEND
)) == -1)
22 err(1, "Cannot open `%s'", fn
);
23 if ((off
= lseek(fd
, (off_t
) 0, SEEK_SET
)) != (off_t
)0)
24 err(1, "Seek failed");
25 if (write(fd
, str
, 0) != 0)
26 err(1, "Write failed");
27 if ((off
= lseek(fd
, (off_t
) 0, SEEK_CUR
)) != (off_t
)0)
28 errx(1, "bad seek offset %lld\n", (long long)off
);
30 err(1, "Close failed");
32 err(1, "Unlink failed");