Introduce old redir program
[lcapit-junk-code.git] / books / apue / hole.c
blobd0c27f0a680b2baaf428c232c58f00579e173867
1 /*
2 * Creates a file with a hole
3 */
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
12 char buf1[] = "abcdefghij";
13 char buf2[] = "ABCDEFGHIJ";
15 int main(void)
17 int fd;
19 if ((fd = creat("file.hole", 0666)) < 0) {
20 perror("creat()");
21 exit(1);
24 if (write(fd, buf1, 10) != 10) {
25 perror("buf1 write error");
26 exit(1);
28 /* offset now == 10 */
30 if (lseek(fd, 40, SEEK_SET) == -1) {
31 perror("lseek()");
32 exit(1);
34 /* offset now == 40 */
36 if (write(fd, buf2, 10) != 10) {
37 perror("buff2 write error");
38 exit(1);
40 /* offset now == 50 */
42 return 0;