|
沙发

楼主 |
发表于 2009-2-8 00:15:56
|
只看该作者
假设下面代码编译得到的程序和一个叫做 test.txt 的文件在同一个目录下,其中的内容是:
ok,the world is good
hell is terrible!
测试代码:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
main()
{
int fd;
off_t offset;
fd = open("test.txt", O_RDONLY);
offset = lseek(fd, -10, SEEK_END);
printf("The offset is %d\\n",offset);
offset = lseek(fd, 5, SEEK_CUR);
printf("The offset is %d\\n",offset);
return 0;
}
运行程序后:[root@localhost LSEEK]# ./lseek.exe
The offset is 29
The offset is 34 |
|