Bug 52507

Summary: ftell returns the wrong thing on stdin
Product: [Retired] Red Hat Raw Hide Reporter: Jonathan Kamens <jik>
Component: libstdc++Assignee: Jakub Jelinek <jakub>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 1.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-01 15:33:42 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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>

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 06:31:55 UTC
assigning to jakub, I have no idea why the bug did end up being assigned to
me...

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
Closed.