Bug 52507 - ftell returns the wrong thing on stdin
ftell returns the wrong thing on stdin
Status: CLOSED NEXTRELEASE
Product: Red Hat Raw Hide
Classification: Retired
Component: libstdc++ (Show other bugs)
1.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-08-24 10:37 EDT by Jonathan Kamens
Modified: 2007-04-18 12:36 EDT (History)
0 users

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


Attachments (Terms of Use)

  None (edit)
Description Jonathan Kamens 2001-08-24 10:37:21 EDT
Compile this test program with "cc":

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

main()
{
  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 02:31:55 EDT
assigning to jakub, I have no idea why the bug did end up being assigned to
me...
Comment 2 Jakub Jelinek 2001-09-18 04:08:55 EDT
This was fixed in libstdc++-2.96-98 on 2001-09-04.
Comment 3 Benjamin Kosnik 2004-10-01 11:33:42 EDT
Closed.

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