X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: ftello/fgetpos bug Date: Fri, 27 Apr 2007 16:40:33 +0000 (UTC) Lines: 48 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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'm not sure if this is a newlib bug, or a cygwin bug in how the 32- vs. 64-bit versions of stdio functions are initialized for std{in,out,err}. For some reason, ftello and fgetpos fail to work on the default stdin, but have no problem once freopen or fopen has been in the loop. I'm still trying to track it down, but thought I'd bring attention to the problem. $ echo hello > blah $ cat foo.c #include #include int main(int argc, char **argv) { fpos_t pos; FILE *f; if (argc > 2) f = freopen(argv[1], "r", stdin); else if (argc > 1) f = fopen(argv[1], "r"); else f = stdin; getc(f); printf("ftell:%d ", (int) ftell(f)); printf("ftello:%d ", (int) ftello(f)); fgetpos(f, &pos); printf("fgetpos:%d ", (int) pos); printf("lseek:%d ", (int) lseek(fileno(f), 0, SEEK_CUR)); return 0; } $ echo hi | ./foo ftell:-1 ftello:-1 fgetpos:-1 lseek:-1 $ # Good - a pipe is not seekable, so there is no position $ ./foo blah a ftell:1 ftello:1 fgetpos:1 lseek:1 $ # Good - freopen makes stdin track seekable position $ ./foo blah ftell:1 ftello:1 fgetpos:1 lseek:1 $ # Good - fopen makes f track seekable position $ ./foo < blah ftell:1 ftello:-1 fgetpos:-1 lseek:1 $ # Ouch - ftell and ftello disagree! -- 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/