Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actual implementation of EOF different from -1

POSIX defines EOF as a macro expanding to a negative value:

The header shall define the following macro which shall expand to an integer constant expression with type int and a negative value:

EOF

End-of-file return value.

In every implementation I could find, EOF is always defined as -1.

Although the standard does allow for different values, I could not find any specific implementation where that happens, and I'd like to find one for testing purposes.1

1I could make my own implementation, but my real purpose is to "find it in the wild", which, due to the impossibility of proving its absence, is the next best thing I can think of.

An almost identical question has already been asked, however there were two questions asked at the end, and the accepted answer only answers the second one (about WEOF). A different user replied to the first question in the negative, but because the question was restricted to common C environments, the negative is arguable correct: -1 is likely to be used in any sensible implementation with small char type.

Since my question is about existence, the only way to actually answer it is to provide an example, so I will rephrase it: please provide an example of an existing implementation where EOF != -1. Be it newlib or musl, PDP or VAX, Plan 9 or Hurd, any combination of libc/hardware/operating system with a POSIX-compatible or ISO C-compatible libc where this happens is valid.

like image 767
anol Avatar asked Feb 02 '18 12:02

anol


People also ask

What is EOF and when it is used?

In computing, end-of-file (EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

When working with files What does EOF or EOF mean?

1. Short for end-of-file, EOF is a code placed by a computer after a file's last byte of data. EOF marks are helpful in data transmission and storage. Files are stored in blocks, and the end marker helps the computer know it has allocated enough space to store the file.

Why is EOF used?

Use EOF to avoid the error generated by attempting to get input past the end of a file. The EOF function returns False until the end of the file has been reached. With files opened for Random or Binary access, EOF returns False until the last executed Get statement is unable to read an entire record.

What is Recordset BOF?

BOF Indicates that the current record position is before the first record in a Recordset object. EOF Indicates that the current record position is after the last record in a Recordset object.


1 Answers

Lazy Sunday, so I found this https://github.com/xinu-os/xinu which comes with this https://github.com/xinu-os/xinu/blob/master/include/stddef.h listing this

#define EOF (-2) /**< End-of-file (usually from read)    */

:-)

Xinu sources dated back to 1987 are here: https://www.tuhs.org//cgi-bin/utree.pl?file=Xinu7 which unfortunately seem to be using -1 as value for EOF. :-(

like image 177
alk Avatar answered Sep 28 '22 18:09

alk