#include "vxworks.h"
#include "stdio.h"
#include "ioLib.h"
#include "sioLib.h"
#include "string.h"
#include "ioctl.h"
#include "selectLib.h"
#include "sys/stat.h"
long get_file_size(char *filename)
{
struct stat f_stat;
if(stat(filename,&f_stat)==-1)
return -1;
return f_stat.st_size;
}
void filetest()
{
int fd;
int wnum;
int rnum;
int len;
long flen;
char *wbuf="hello world!";
char rbuf[100];
len=strlen(wbuf);
printf("len-->%d\n",len);
fd=creat("/tffs0/testdir/1.txt",O_RDWR);
if(fd==ERROR)
printf("creat error!\n");
else{
fd=open("/tffs0/testdir/1.txt",O_RDWR,0);
if(fd==ERROR)
printf("open error!\n");
else
{
printf("%s\n",wbuf);
wnum=write(fd,wbuf,len);
printf("wnum-->%d\n",wnum);
flen=get_file_size("/tffs0/testdir/1.txt");
printf("file len-->%d\n",flen);
rnum=read(fd,rbuf,len-1);
printf("rnum-->%d\n",rnum);
rbuf[len]=0;
printf("%s\n",rbuf);
close(fd);
}
}
}
void readfile()
{
char rbuf[100];
FILE* fd;
int rnum;
long flen;
fd=fopen("/tffs0/testdir/1.txt","r");
if(fd==NULL)
printf("open error!\n");
else
{
flen=get_file_size("/tffs0/testdir/1.txt");
printf("file len-->%d\n",flen);
rnum=fread(rbuf,flen,1,fd);
printf("rnum-->%d\n",rnum);
rbuf[flen]=0;
printf("%s\n",rbuf);
fclose(fd);
}
}
void readfile2()
{
char rbuf[100];
int fd;
int rnum;
long flen;
fd=open("/tffs0/testdir/1.txt",O_RDWR,0);
if(fd==ERROR)
printf("open error!\n");
else
{
flen=get_file_size("/tffs0/testdir/1.txt");
printf("file len-->%d\n",flen);
rnum=read(fd,rbuf,flen);
printf("rnum-->%d\n",rnum);
rbuf[rnum]=0;
printf("%s\n",rbuf);
close(fd);
}
}
阅读(2524) | 评论(0) | 转发(0) |