Bug 52507 - ftell returns the wrong thing on stdin
Summary: ftell returns the wrong thing on stdin
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: libstdc++   
(Show other bugs)
Version: 1.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2001-08-24 14:37 UTC by Jonathan Kamens
Modified: 2007-04-18 16:36 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-01 15:33:42 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Jonathan Kamens 2001-08-24 14:37:21 UTC
Compile this test program with "cc":

---cut here---
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

  int real_position = lseek(fileno(stdin), 0, SEEK_CUR);
  int stdio_position = ftell(stdin);

  printf("really = %d, stdio = %d\n", real_position, stdio_position);
---cut here---

Then run "(cat >/dev/null; ./a.out) < foo", where "foo" is any non-empty
file.  It will print two identical numbers for "really" and "identical".

Now compile the same test program, this time using "c++" instead of "cc". 
This time, when you run the same test command, the "stdio" number will be 0
instead of matching the "really" number.

In short, ftell() in libstdc++ is not doing the right thing if the file
descriptor is at a non-zero position before stdio gets its hands on it.

This has real ramifications.  For one thing, it broke ghostscript (see bug
52505, which I just filed about this).

Comment 1 Cristian Gafton 2001-09-14 06:31:55 UTC
assigning to jakub, I have no idea why the bug did end up being assigned to

Comment 2 Jakub Jelinek 2001-09-18 08:08:55 UTC
This was fixed in libstdc++-2.96-98 on 2001-09-04.

Comment 3 Benjamin Kosnik 2004-10-01 15:33:42 UTC

Note You need to log in before you can comment on or make changes to this bug.