代码来自
char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
int
main(int argc, char *argv[])
{
int fd;
if((fd = creat("file.hole", 0777)) < 0)
perror("creat error");
if(write(fd, buf1, 10) != 10)
perror("buf1 write error");
if(lseek(fd, 04000, SEEK_SET) == -1)
perror("lseek error");
if(write(fd, buf2, 10) != 10)
perror("buf2 write error");
exit(EXIT_SUCCESS);
}
读取文件
od -c 文件.hole
和输出:
0000000 a b c d e f g h i j \0 \0 \0 \0 \0 \0
0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0004000 A B C D E F G H I J
0004012
如果我删除 lseek 并创建 file.nohole,输出将是
0000000 a b c d e f g h i j A B C D E F
0000020 G H I J
0000024
有两个问题让我很困惑。
> 1.At output1, why there are 30 * '\0' after j
> 2.output1: why file ends with 0004012 not 0004010