Bug 569697

Summary: getc says EOF, feof disagrees
Product: [Fedora] Fedora Reporter: Tom Lane <tgl>
Component: glibcAssignee: Andreas Schwab <schwab>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 11CC: fweimer, hhorak, jakub, schwab
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-03-02 10:14:48 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:
Attachments:
Description Flags
bogus.c none

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?