On Nov 14 02:19, Dave Korn wrote: > Eric Blake wrote: > > > According to Salvador Fandino on 11/13/2009 1:36 PM: > > >> Using ftell() after fopen(..., "a") returns 0 even when the file open for > >> appending is not empty. AFAIK, it should return the size of the file. > > > > Not a bug. POSIX allows this behavior, and Linux does it as well. POSIX > > also allows BSD behavior of seeking to the end, although this is less > > friendly to reading back a file opened with fopen(...,"a+"). So portable > > programs can't expect either situation, and you MUST use fseek when > > opening for append if you expect a particular position. > > I'm really confused; aren't you saying that there is exactly no difference > between opening for append and just opening in ordinary r/w mode? I always > thought the positioning of the write pointer immediately after open was the > only possible difference there could be.
Eric is just saying that you can't rely on certain values of the file offset at any given time, except at write(2) time. There's no good reason to seek the file offset to the end of the file right at (f)open time, even if "a"/O_APPEND has been specified. See the POSIX open(2) man page: O_APPEND If set, the file offset shall be set to the end of the file prior to each write. Note "prior to each write". See the POSIX fopen(2) man page: Opening a file with append mode (a as the first character in the mode argument) shall cause all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to fseek(). Same here. POSIX doesn't specify any other time at which the position has to be set to EOF. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple