fgets() - Watcom C 10.6

The documentation for fgets() says:
The fgets() function returns buf if successful.

NULL is returned if end-of-file is encountered, or a read error
occurs. When an error has occurred, errno contains a value
indicating the type of error that has been detected.

I interpreted this to mean if end-of-file is encountered, NULL would be
returned, but errno would be set to EOK (no error). However, errno
appears to be set to EACCESS when end-of-file is encountered. Is this
correct?

How does one distinquish between end-of-file and a true EACCESS
(assuming it is a valid error type for fgets())?


Bob Harris In short, you may buy a servant or slave,
Bath, NH but you cannot buy a friend.
bob@microprograms.com (Thoreau: Wild Fruits)

Previously, Robert L. Harris wrote in qdn.public.qnx4:

The documentation for fgets() says:
The fgets() function returns buf if successful.

NULL is returned if end-of-file is encountered, or a read error
occurs. When an error has occurred, errno contains a value
indicating the type of error that has been detected.

I interpreted this to mean if end-of-file is encountered, NULL would be
returned, but errno would be set to EOK (no error). However, errno
appears to be set to EACCESS when end-of-file is encountered. Is this
correct?

Are you sure it wasn’t EACCESS before fgets() was called? Try
setting errno to EOK before calling fgets().

How does one distinquish between end-of-file and a true EACCESS
(assuming it is a valid error type for fgets())?


Bob Harris In short, you may buy a servant or slave,
Bath, NH but you cannot buy a friend.
bob@microprograms.com > (Thoreau: Wild Fruits)


Sam Roberts <sroberts@uniserve.com> (http://www.emyr.net/Sam)

Robert L. Harris <bob@microprograms.com> wrote:

The documentation for fgets() says:
The fgets() function returns buf if successful.

NULL is returned if end-of-file is encountered, or a read error
occurs. When an error has occurred, errno contains a value
indicating the type of error that has been detected.

I interpreted this to mean if end-of-file is encountered, NULL would be
returned, but errno would be set to EOK (no error). However, errno
appears to be set to EACCESS when end-of-file is encountered. Is this
correct?

The C standard specifically says that standard functions aren’t allowed
to set errno to zero, but are in general allowed to set it to any other
value on success. Unless you know that our implementation of fgets()
doesn’t touch errno on success, it’s impossible to reliably find out
whether there was an error or not by just looking at errno.

How does one distinquish between end-of-file and a true EACCESS
(assuming it is a valid error type for fgets())?

Use feof() and/or ferror().

\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.