delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/09/07/17:25:22

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: stdio bug
Date: Thu, 7 Sep 2006 21:24:33 +0000 (UTC)
Lines: 46
Message-ID: <loom.20060907T215834-908@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

POSIX requires "When a standard utility reads a seekable input file and 
terminates without an error before it reaches end-of-file, the utility shall 
ensure that the file offset in the open file description is properly positioned 
just past the last byte processed by the utility."

For an example, POSIX requires these two commands to give the same results:
$ echo 1 2 3 | tr ' ' '\n' > file
$ tail -n +2 file
2
3
$ (sed -n 1q; cat) < file
2
3

On cygwin, this isn't happening:

$ (sed -n 1q; cat) < file
$

But on Solaris, it is:

$ (truss sed -n 1q; cat) < file 2>&1 | tail
fstat64(0, 0xFFBEED40)                          = 0
brk(0x00042100)                                 = 0
brk(0x00044100)                                 = 0
read(0, " 1\n 2\n 3\n", 8192)                   = 6
close(1)                                        = 0
close(2)                                        = 0
llseek(0, 0xFFFFFFFFFFFFFFFC, SEEK_CUR)         = 2
_exit(0)
2
3

Notice the llseek(0,-4,SEEK_CUR) just before _exit, which restored the file 
pointer back to the last character consumed, so that cat could then start up 
from the right location.

I don't know whether a fix to this would lie in fclose() (making sure that on 
input streams, the position of the underlying fd is restored when discarding 
buffered data), or somewhere else, but it would be nice to see this fixed.  And 
it seems like the bug is in cygwin, not sed, since it is the same version of 
GNU sed on both machines.

-- 
Eric Blake



--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019