File: [Development] / xfs-cmds / xfstests / src / mmapcat.c (download)
Revision 1.2, Tue Jun 18 11:55:12 2002 UTC (15 years, 4 months ago) by lord
Branch: MAIN
Changes since 1.1: +16 -11
lines
make this run at a reasonable speed - say a few hundred times faster
|
/* mmapcat.c - derived from source by misiek@pld.ORG.PL */
#include<fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int fd,n;
char *ptr, *ptr2;
struct stat st;
fd=open(argv[1],O_RDONLY);
if(fd<0) {
perror(argv[1]);
exit(1);
}
fstat(fd,&st);
if(st.st_size%4096==0) {
fprintf(stderr,"bad file size!\n");
exit(1);
}
ptr2 = ptr = mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
while (*ptr!=0) ptr++;
write(1,ptr2,ptr - ptr2);
exit(0);
}