|
[root@Nirvana code]# gcc -o lseek lseek.c ourhdr.h
gcc: compilation of header file requested
这是unix环境高级编程上的 ourhdr。h在本目录下
lseek.c:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ourhdr.h"
char buf1[]="abcdefghij";
char buf2[]="ABCDEFGHIJ";
int main(void){
int fd;
if((fd=creat("file.hole",S_IRWXO))<0)
err_sys("buf1 write error");
if(write(fd,buf1,10)!=10)
err_sys("buf1 write error");
/*offset=10*/
if(lseek(fd,40,SEEK_SET)==-1)
err_sys("lseek error!");
/*offset=40*/
if(write(fd,buf2,10)!=10)
err_sys("buf2 write error");
/*offset=50*/
exit(0);
} |
|