/* randread.c by Michael Thorpe 2005-12-04 */ #include #include #include #include #include #include #include int main(int argc,char **argv) { int b,c,fd,i,loc,size; if(argc != 3) { fprintf(stderr,"usage: %s \n",argv[0]); return(1); } if(-1==(fd=open(argv[1],O_RDONLY))) { fprintf(stderr,"Couldn't open %s (errno %d)\n",argv[1],errno); return(-1); } size=atoi(argv[2]); for(i=0;i<10000;i++) { loc=rand()%(size-4); if(-1==lseek(fd,loc,SEEK_SET)) { fprintf(stderr,"Couldn't seek to %d (errno %d)\n",loc,errno); return(-1); } if(4 != read(fd,&b,4)) { fprintf(stderr,"Couldn't read at %d (errno %d)\n",loc,errno); return(-1); } c+=b; } return(0); }