This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[OT] RE: Expected behaviour of fgets on stdin after a EOF ?


> -----Original Message-----
> From: cygwin-owner On Behalf Of Dave Korn
> Sent: 18 October 2004 18:54

[ OT tagged, because this is all standard c programming / library / posix
stuff and not cygspecific.  If you want to discuss further,
http://cygwin.com/acronyms#TITTTL! ]

> > -----Original Message-----
> > From: cygwin-owner On Behalf Of Laurent Lagosanto
> > Sent: 18 October 2004 18:48
> 
> 
> > Am I doing something wrong with fgets ?
> 
>   What part of "END of file" don't you get?

  :)

  For the serious answer, see the SUS definition of fgets...

http://www.opengroup.org/onlinepubs/009695399/functions/fgets.html

(although for preference you really want to refer to the C language spec, to
which the SUS defers: nonetheless, they're both in fairly clear agreement
that) once the input stream has reached EOF, the c library should set an
end-of-file-indicator in the stream (FILE struct) and not start returning
more input.

> Looks like (confirmed with GDB), that fgets is no longer 
> blocking after 
> the EOF, and keeps returning the same NULL value, while it's 
> blocking on other platforms I've mentioned.

  This is consistent with what the spec requires:

"Description
2 The fgets function reads at most one less than the number of characters
specified by n from the stream pointed to by stream into the array pointed
to by s. No additional characters are read after a new-line character (which
is retained) or after end-of-file. A null character is written immediately
after the last character read into the array."

  That says to me that anytime after you've received an EOF, fgets is not
allowed to read or return "additional characters".

"Returns
3 The fgets function returns s if successful. If end-of-file is encountered
and no characters have been read into the array, the contents of the array
remain unchanged and a null pointer is returned. If a read error occurs
during the operation, the array contents are indeterminate and a null
pointer is returned"

  That says to me that once EOF has been reached, it should stay EOF'd.



    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]