#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/*********************
*file: lseek.c
*author:QG
*time:2015-05-11
*description:
**********************/
int main()
{
char *in = "./123.txt";
//char *in = "1234567890abcdefghijklmnopqrstuvwxyz";
char buf[10];
int a = 0;
int c = 0;
int d = 0;
a = open(in,O_RDWR|O_CREAT,0755);
if(a < 0)
{
printf("open in fail!\n");
}
else if(a > 0)
{
printf("open in OK,descriptor is %d!\n",a);
}
c = lseek(a,4,SEEK_SET);
if(c < 0)
{
printf("lseek fail!\n");
}
else if(c > 0)
{
printf("lseek is OK,location is %d bytes from in!\n",c);
}
d = read(a,buf,3);
buf[3]='\0';
if(d < 0)
{
printf("read fail!\n");
}
else if(d > 0)
{
printf("read is OK,read %d bytes from in!\n",d);
printf("read buf :%s!\n",buf);
}
return(0);
}
系统调用 6--lseek
最新推荐文章于 2024-04-05 13:37:55 发布