From owner-freebsd-stable Wed Jun 27 23:21:53 2001 Delivered-To: freebsd-stable@freebsd.org Received: from www.mmlab.cse.yzu.edu.tw (www.mmlab.cse.yzu.edu.tw [140.138.145.166]) by hub.freebsd.org (Postfix) with SMTP id 7C73137B403 for ; Wed, 27 Jun 2001 23:21:05 -0700 (PDT) (envelope-from avatar@mmlab.cse.yzu.edu.tw) Received: (qmail 72343 invoked from network); 28 Jun 2001 06:20:17 -0000 Received: from www.mmlab.cse.yzu.edu.tw (@140.138.145.166) by www.mmlab.cse.yzu.edu.tw with SMTP; 28 Jun 2001 06:20:17 -0000 Date: Thu, 28 Jun 2001 14:20:17 +0800 (CST) From: Tai-hwa Liang To: Subject: lseek(SEEK_END) then read()... bug of feature? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 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.... I've also tested this code on Linux(2.4.x) and Windoze 98. It seemed that all read() returned correct result. Did I misunderstand the meaning of lseek(2)? ------------------------------------------------------------------------ #include #include #include int main() { unsigned int l = 0; off_t offset; int ret, fd = open("/kernel", O_RDONLY); offset = 0 - sizeof(int); lseek(fd, offset, SEEK_END); if ((ret = read(fd, &l, sizeof(int))) != sizeof(int)) perror("read error in phase 1"); else printf("read %d bytes in phase 1\n", ret); offset = -4; lseek(fd, offset, SEEK_END); if ((ret = read(fd, &l, sizeof(int))) != sizeof(int)) perror("read error in phase 2"); else printf("read %d bytes in phase 2\n", ret); printf("result = 0x%x\n", l); close(fd); return (0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message