stream.getc() doesn't recognize eof
Brian White
bcwhite at pobox.com
Wed Mar 12 14:16:53 PDT 2008
I was looking through the std.stream code of Phobos and found this function:
// reads and returns next character from the stream,
// handles characters pushed back by ungetc()
// returns char.init on eof.
char getc() {
char c;
if (prevCr) {
prevCr = false;
c = getc();
if (c != '\n')
return c;
}
if (unget.length > 1) {
c = cast(char)unget[unget.length - 1];
unget.length = unget.length - 1;
} else {
readBlock(&c,1);
}
return c;
}
Is there something I don't understand? How does it recognize EOF? The
"readBlock" function is defined as returning 0 (zero) if there is no
more data but its return value in not checked.
-- Brian
More information about the Digitalmars-d-learn
mailing list