一、源代码
1 #include "apue.h"
2 #include <fcntl.h>
3
4 int main()
5 {
6 char buf1[] = "abcdefj";
7 char buf2[] = "ABCDEFJ";
8 int fd;
9 if ( fd = creat ( "file.hole", FILE_MODE ) < 0 )
10 err_sys("cannot create file");
11 if(write(fd,buf1,10) != 10 )
12 err_sys("writei buf1 error");
13 if ( lseek(fd, 16384, SEEK_SET) == -1 )
14 err_sys("lseek error");
15 if ( write(fd, buf2, 10) != 10 )
16 err_sys("write buf2 error");
17
18 exit(0);
19 }
20
二、运行结果
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:./3_2
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:ls -l file.hole
-rw-r--r-- 1 tingbinz tingbinz 16394 Sep 6 03:36 file.hole
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:cat file.hole
abcdefjABCDEFJab<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:od file.hole
0000000 060542 061544 062546 065000 000000 000000 000000 000000
0000020 000000 000000 000000 000000 000000 000000 000000 000000
*
0040000 040502 041504 042506 045000 060542
0040012
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:od -c file.hole
0000000 a b c d e f j \0 \0 \0 \0 \0 \0 \0 \0 \0
0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0040000 A B C D E F J \0 a b
0040012
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G: