Sync usage with man page.
[netbsd-mini2440.git] / regress / sys / kern / write_append / write_append.c
blobe8b172ad3cfe25324011874a8e945a3b979a0cca
1 #include <err.h>
2 #include <unistd.h>
3 #include <fcntl.h>
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;
9 int
10 main(void)
12 int fd;
13 off_t off;
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");
19 if (close(fd) == -1)
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);
29 if (close(fd) == -1)
30 err(1, "Close failed");
31 if (unlink(fn) == -1)
32 err(1, "Unlink failed");
33 return 0;