X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com Subject: lseek + read = ENOENT Mail-Copies-To: never Reply-To: sds AT gnu DOT org X-Attribution: Sam X-Disclaimer: You should not expect anyone to agree with me. From: Sam Steingold Mail-Followup-To: cygwin AT cygwin DOT com Date: Thu, 19 Jan 2006 16:10:25 -0500 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I cannot read the last 4-byte word in a file using lseek + read: /* file "foo" exists and is large enough - say, 4 MB */ int fd = open("foo",O_RDONLY|O_BINARY); uint32 data; /* this succeeds and correctly returns the size of file "foo" minus 4 */ lseek(fd,-sizeof(data),SEEK_END); /* this returns 0 -- instead of the expected 4 -- and sets errno to ENOENT */ read(fd,&data,sizeof(data)); if I run this under gdb and type lseek(fd,-sizeof(data),SEEK_END); read(fd,&data,sizeof(data)); several times, eventually read() starts to return 4 and set data to the value I actually wrote into "foo" last. I observe this on linux, cygwin and solaris -- what am I doing wrong? Thanks! -- Sam Steingold (http://www.podval.org/~sds) running w2k http://truepeace.org http://www.savegushkatif.org http://www.palestinefacts.org http://www.openvotingconsortium.org http://www.dhimmi.com http://www.camera.org When we break the law, they fine us, when we comply, they tax us. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/