Date: Thu, 28 Jun 2001 14:20:17 +0800 (CST) From: Tai-hwa Liang <avatar@mmlab.cse.yzu.edu.tw> To: <freebsd-stable@FreeBSD.org> Subject: lseek(SEEK_END) then read()... bug of feature? Message-ID: <Pine.BSF.4.33.0106281339090.72014-100000@www.mmlab.cse.yzu.edu.tw>
next in thread | raw e-mail | index | archive | help
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 <fcntl.h> #include <stdio.h> #include <unistd.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.33.0106281339090.72014-100000>