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 Date: Wed, 10 Jul 2002 19:04:59 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: [BUG] open(): Opening with flags O_RDONLY | O_APPEND positions the file pointer at the end of the file Message-ID: <20020710190459.L24137@cygbert.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <823876622 DOT 20020710153943 AT syntrex DOT com> <20020710163613 DOT GD10966 AT redhat DOT com> <20020710184830 DOT J24137 AT cygbert DOT vinschen DOT de> <20020710165014 DOT GB11381 AT redhat DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020710165014.GB11381@redhat.com> User-Agent: Mutt/1.3.22.1i On Wed, Jul 10, 2002 at 12:50:14PM -0400, Chris Faylor wrote: > On Wed, Jul 10, 2002 at 06:48:30PM +0200, Corinna Vinschen wrote: > >On Wed, Jul 10, 2002 at 12:36:13PM -0400, Chris Faylor wrote: > >> On Wed, Jul 10, 2002 at 03:39:43PM +0200, Pavel Tsekov wrote: > >> >Hello, there :) > >> > > >> >Attached is a testcase which displays the problem. On Linux it will > >> >properly return 13, while on cygwin it returns 0. > >> > > >> >I found this while trying to understand why MC doesn't extract > >> >properly files from say .zip files. > >> > > >> >I don't know exactly why they call O_RDONLY combined with O_APPEND but > >> >I will mail the mc-devel list ASAP. > >> > > >> >Still according to the Linux man page and SUSv2, O_APPEND should be > >> >taken into account only when writing to the file. > >> > > >> >Having in mind that fhandler_base::write() calls SetFilePointer > >> >before each write, I wonder why fhandler_disk_base::open calls > >> >SetFilePointer when it detects O_APPEND ? > >> > >> Good question. > > > >What if > > > > fd = open(O_APPEND); > > pos = lseek(fd, 0, SEEK_CUR); > > > >? If open() doesn't move the pointer, `pos' is incorrectly set to 0. > > Actually, I'd argue that, in that case, lseek should have some O_APPEND > logic of its own. Just checked the following on Linux: #include #include int main() { int fd; off_t pos; fd = open ("x.c", O_APPEND); if (fd >= 0) { pos = lseek (fd, 0, SEEK_CUR); printf ("pos1: %ld\n", pos); pos = lseek (fd, 0, SEEK_END); printf ("pos2: %ld\n", pos); pos = lseek (fd, 0, SEEK_SET); printf ("pos3: %ld\n", pos); close (fd); } return 0; } Output: pos1: 0 pos2: 382 pos3: 0 So open() doesn't set the pointer. And lseek() doesn't take O_APPEND into account either. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:cygwin AT cygwin DOT com Red Hat, Inc. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/