Bug 569697 - getc says EOF, feof disagrees
Summary: getc says EOF, feof disagrees
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 11
Hardware: x86_64
OS: Linux
low
medium
Target Milestone: ---
Assignee: Andreas Schwab
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-03-02 04:17 UTC by Tom Lane
Modified: 2016-11-24 15:52 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2010-03-02 10:14:48 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
bogus.c (240 bytes, text/plain)
2010-03-02 04:17 UTC, Tom Lane
no flags Details

Description Tom Lane 2010-03-02 04:17:54 UTC
Created attachment 397238 [details]
bogus.c

Description of problem:
The attached program demonstrates that if one opens a directory for reading, getc() returns EOF,
but feof() doesn't think the file is at EOF.  I realize that reading a directory via stdio isn't a very useful operation, but couldn't one expect some consistency here?  The consistency failure sends at least one widely-used program into an infinite loop.

Version-Release number of selected component (if applicable):
glibc-2.10.2-1.x86_64

How reproducible:
100%

Steps to Reproduce:
1.  Run attached program
  
Actual results:
$ ./a.out
getc yields -1
feof yields 0

Expected results:
If getc yields -1, shouldn't feof yield 1?

Additional info:
The same behavior was reported to me by someone running CentOS 5.2 on x86_64, so I suspect it affects many versions of glibc.

Comment 1 Andreas Schwab 2010-03-02 10:14:48 UTC
The program is bogus, you didn't check ferror.

Comment 2 Tom Lane 2010-03-02 14:30:59 UTC
If it's not going to let me read, why didn't the fopen fail?


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