|
|
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<sys/uio.h>
struct testvector {
int a;
char b[10];
};
//#define LEN (sizeof(struct testvector))
int main(){
int fd=open("files.txt",O_RDWR|O_CREAT|O_TRUNC,0644);
struct iovec iv,iv2;
struct testvector xx,pxx;// if use malloc,then here is *pxx
int LEN=sizeof(struct testvector);
xx.a=100;
strcpy(xx.b,"aaaaaa");
iv.iov_base=&xx;
iv.iov_len=LEN;
writev(fd, &iv,1);
close(fd);
fd=open("files.txt",O_RDONLY);
iv2.iov_base=&pxx; // malloc(LEN);
iv2.iov_len=LEN;
readv(fd, &iv2,1);
// pxx=(struct testvector *)(iv2.iov_base);
printf("%d--%s\n",pxx.a,pxx.b);
// printf("%d--%s\n",pxx->a,pxx->b);
return 0;
} |
|