[BACK]Return to mmapcat.c CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfstests / src

File: [Development] / xfs-cmds / xfstests / src / mmapcat.c (download)

Revision 1.4, Mon May 19 04:56:35 2003 UTC (14 years, 5 months ago) by nathans
Branch: MAIN
CVS Tags: XFS-1_3_0pre1, HEAD
Changes since 1.3: +3 -2 lines

QA source updates and some associated test changes

/* mmapcat.c - derived from source by misiek@pld.ORG.PL */

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
	int fd;
	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);
}