From owner-FreeBSD-users-jp@jp.freebsd.org  Mon Oct 28 13:33:58 1996
Received: by jaz.jp.freebsd.org (8.7.3+2.6Wbeta5/8.7.3) id NAA05895
	Mon, 28 Oct 1996 13:33:58 +0900 (JST)
Received: by jaz.jp.freebsd.org (8.7.3+2.6Wbeta5/8.7.3) with SMTP id NAA05890
	for <FreeBSD-users-jp@jp.freebsd.org>; Mon, 28 Oct 1996 13:33:57 +0900 (JST)
Received: from isrdgw.isrd.hitachi.co.jp by hitiij.hitachi.co.jp (8.6.12+2.4W/3.4W-hitiij) id NAA21795; Mon, 28 Oct 1996 13:32:08 +0900
Received: from [133.144.95.254] by isrdgw.isrd.hitachi.co.jp (8.6.9+2.4W/2.7W-ISRD)
	id NAA22624; Mon, 28 Oct 1996 13:32:39 +0900
Message-Id: <199610280432.NAA22624@isrdgw.isrd.hitachi.co.jp>
To: FreeBSD-users-jp@jp.freebsd.org
Date: Mon, 28 Oct 1996 13:29:06 +0900
From: Kazuo HORIKAWA <horikawa@isrd.hitachi.co.jp>
Reply-To: FreeBSD-users-jp@jp.freebsd.org
X-Distribute: distribute [version 2.1 (Alpha) patchlevel=19]
X-Sequence: FreeBSD-users-jp 5552
Subject: [FreeBSD-users-jp 5552] mmap(2) and/or cmp(1) problem on FreeBSD 2.1.5R
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

 $BKY@n!wF|N)$G$9!#$3$l$C$F(B mmap(2) cmp(1) $B$I$A$i$NLdBj$G$7$g$&!)(B

$B!t(B http://zephyr.elcom.nitech.ac.jp/~yuki/FreeBSD/WAISSearch-jp.cgi
$B!t(B $B$OD4$Y$^$7$?$,J,$+$j$^$;$s$G$7$?!#(B



 FreeBSD 2.1.5R $B$N(B mmap(2) $B$H(B cmp(1) $B$NLdBj(B(WC $B$N(B CD $B$+$i%$%s%9%H!<%k(B)

mmap(2) $B$N%^%K%e%"%k$K$O(B

SYNOPSIS
     #include <sys/types.h>
     #include <sys/mman.h>

     caddr_t
     mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)

DESCRIPTION
     The mmap function causes the pages starting at addr and continuing for at
     most len bytes to be mapped from the object described by fd, starting at
     byte offset offset. If offset or len is not a multiple of the pagesize,
     the mapped region may extend past the specified range.

$B$H=q$$$F$"$j$^$9$,!"(Boffset $B$K(B 4096 $B$NG\?t0J30$r;XDj$9$k$H!"(Bmmap() $B$O<:(B
$BGT$9$k$h$&$G$9!#(B

 mmap(2) $B$N<BAu$K$h$C$F$O(B offset $B$H(B len $B$K%Z!<%8%5%$%:$NG\?t0J30$r;XDj(B
$B$9$k$H(B EINVAL $B$rJV$9$b$N$b$"$k$=$&$J$N$G$9$,!"(BFreeBSD 2.1.5R $B$b$=$&$J(B
$B$N$G$7$g$&$+!)(B

 $B0J2<$N%W%m%0%i%`(B(a.out $B$H$9$k(B)$B$r<B9T$9$k$H(B 
"a.out: /var/log/messages: Invalid argument" $B$HI=<($5$l$^$9!#(B
$B!A!A$3$3$+$i!A!A(B
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
main()
{
	char *file;
	int fd;
	u_char *p1;

	file = "/var/log/messages";
	fd = open(file, O_RDONLY, 0);
	if((p1 = (u_char *)mmap(NULL,
	(size_t) 1, PROT_READ, 0, fd, 4095)) == (u_char *)-1)
		err(2, "%s", file);
}
$B!A!A$3$3$^$G!A!A(B
offset $B$r(B 4096 $B$K$9$k$H!"I=<($O9T$o$l$^$;$s!#(B


 $B$H$3$m$G!"(Bcmp(1) $B%3%^%s%I$OFbIt$G(B mmap(2) $B$r;HMQ$7$F$$$^$9(B(c_regular()
in regular.c)$B!#(B
 "cmp [-l | -s] file1 file2 [skip1 [skip2]]"$B$H$$$&7A<0$G!"(Bskip1, skip2 
$B$GHf3S3+;O0LCV$r;XDj$G$-$^$9!#(Bskip1, skip2 $B$O(B mmap(2) $B$N(B offset $B$K$J$j(B
$B$^$9!#$=$N$?$a!"(Bskip1, skip2 $B$K(B 4096 $B$NG\?t0J30$r;XDj$9$k$H(B cmp $B$O%(%i!<(B
$B=*N;(B($BNc$($P(B "cmp: file1: Invalid argument" $B$HI=<((B)$B$7$^$9!#(B

 $B$^$?(B skip1, skip2 $B$K$O!"(B8 $B?J?t!"(B16 $B?J?t$b;XDj$G$-$k$H%^%K%e%"%k$K$O5-(B
$B:\$5$l$F$$$^$9$,!"<B:]$O(B 10 $B?J?t$7$+;XDj$G$-$^$;$s!#(B
--
$BKY@nOBM:(B
