#include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char* argv[]){ if(argc != 2) { fprintf(stderr,"Usage: %s \n",argv[0]); exit(1); } int fd = open(argv[argc-1],O_RDONLY); if (fd==-1) { perror("open"); return 1; } struct stat status; if(-1 == fstat(fd,&status)){ perror("fstat"); return 1; } char* mem=(char*) mmap(NULL, status.st_size+10000, PROT_READ, MAP_PRIVATE,fd,0); if(mem == MAP_FAILED){ perror("mmap"); return 1; } int n; if ( -1 == (n=write(1,mem, status.st_size+10000))) { perror("write"); return 1; } printf("\nn=%d\n",n); if( -1 == (n=write(1,mem+n, status.st_size+10000-n))) { perror("write"); return 1; } printf("\nn=%d\n",n); return 0; }