From owner-freebsd-stable Thu Jun 28 7:53:41 2001 Delivered-To: freebsd-stable@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id 82EFD37B405 for ; Thu, 28 Jun 2001 07:53:36 -0700 (PDT) (envelope-from jdp@wall.polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.11.3/8.11.1) with ESMTP id f5SEqxD09887; Thu, 28 Jun 2001 07:52:59 -0700 (PDT) (envelope-from jdp@wall.polstra.com) Received: (from jdp@localhost) by vashon.polstra.com (8.11.3/8.11.0) id f5SEqxf93857; Thu, 28 Jun 2001 07:52:59 -0700 (PDT) (envelope-from jdp) Date: Thu, 28 Jun 2001 07:52:59 -0700 (PDT) Message-Id: <200106281452.f5SEqxf93857@vashon.polstra.com> To: stable@freebsd.org From: John Polstra Cc: avatar@mmlab.cse.yzu.edu.tw Subject: Re: lseek(SEEK_END) then read()... bug of feature? In-Reply-To: References: Organization: Polstra & Co., Seattle, WA Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In article , Tai-hwa Liang wrote: > Hi, > > Anyone tried lseek() from the end of file then read something > out? I've tested the attached code on FreeBSD 4-stable. Both of the two > -stable box(cvsupped on May-02-2001 and Jun-19-2001) prints error > message(Undefined error: 0) on the first read(); however, the second > read() worked without any problem.... It is caused by a bug in your program. > #include > #include > #include > > int > main() > { > unsigned int l = 0; > off_t offset; > int ret, fd = open("/kernel", O_RDONLY); > > offset = 0 - sizeof(int); Due to C's type promotion rules, this assigns the value 4294967292 to "offset". Change it to this: offset = (off_t)0 - sizeof(int); and your program works fine. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Disappointment is a good sign of basic intelligence." -- Chögyam Trungpa To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message