Date: Thu, 12 Aug 1999 11:25:37 +0400 (MSD) From: Oleg Derevenetz <oleg@oleg.sani-c.vrn.ru> To: freebsd-hackers@freebsd.org Subject: mmap bug Message-ID: <Pine.BSF.4.05.9908121122210.347-100000@oleg.sani-c.vrn.ru>
next in thread | raw e-mail | index | archive | help
Oh, I'm sorry, I made a mistake when posting code. I posted incorrectly patched version... This version correct : #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/mman.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> main(int argc, char *argv[]) { int fd; int i; int len=1024*1024*10; /*ie 10Mbytes*/ caddr_t addr; char ttt[80]; int bunlink=0; if (argc>1 && strcmp (argv[1], "-u")==0) bunlink=1; for (i=0;;i++) { sprintf (ttt,"%d",i); printf ("mmapping %ld byte region on file %s\n", len, ttt); fd=open(ttt,O_CREAT|O_RDWR,0666); if (fd<0) { printf("open error %ld\n",errno); exit(1); } lseek(fd,len-1,SEEK_SET); write(fd,"",1); addr=mmap(0,len,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); if (addr==MAP_FAILED) { printf("mmap error %ld",errno); exit(1); } memset(addr,'x',len); if ( munmap(addr, len) != 0 ) { fprintf(stderr, "munmap failed\n"); exit(EXIT_FAILURE); } close(fd); if ( bunlink ) unlink (ttt); } } Thank you for answers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9908121122210.347-100000>