Some OSs allow you fopen a directory, which could cause confusion. This
doesn't make sense for Mercury file streams so test for and raise an error
when this happens.
library/io.m:
fstat files as we open them to determine if they are directories, if
they are close them and return an error.
tests/general/read_dir_regression.m:
tests/general/read_dir_regression.exp:
tests/general/read_dir_regression.exp2:
tests/general/read_dir_regression.exp3:
tests/general/read_dir_regression.exp4:
Update test case, differentiate between errors opening the file, and
reading from the file.
Mercury did not properly test for I/O errors for file reading. If an I/O
error occurred it would be reported as EOF. If this happened at just the
right spot it could be silently ignored. I found the mistake when trying to
open a directory as a file. Opening the file succeeded but reading from it
incorrectly gave an EOF.
library/io.m:
read_char_code has always been documented as returning -1 for EOF
and -2 for an error. But the C code did not correctly implement
this. fgetc will return EOF in either case and the caller must use
ferror or feof to determine what has happened.
Make it clearer that valid characters and bytes from read_char_code
must be >= 0.
Conform to changes in the runtime regarding supporting ferror
runtime/mercury_library_types.h:
Add MR_FERROR macro
Add ferror field to the MercuryFile struct.
runtime/mercury_file.[ch]:
Add ferror field to the MercuryFile struct.
tests/general/Mmakefile:
tests/general/read_dir_regression.exp:
tests/general/read_dir_regression.exp2:
tests/general/read_dir_regression.exp3:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
Add regression test.
tests/.gitignore
Add *.java_date to .gitignore.