fclose returns 0 if the file is successfully closed.
Example
import standard.C.io
class Main {
function Main() {
// Open for read (will fail if file "test1.txt" does not exist)
if(!(var fd1 = fopen( "test1.txt", "r" )))
echo "The file 'test1.txt' was not opened\n";
else {
echo "The file 'test1.txt' was opened\n";
// Close the file
if(fclose(fd1) != 0)
echo "The file 'test1.txt' was not closed\n";
}
// Open for write
if(!(var fd2 = fopen( "test2.txt", "w+" )))
echo "The file 'test2.txt' was not opened\n";
else {
echo "The file 'test2.txt' was opened\n";
// Close the file
if(fclose(fd2) != 0)
echo "The file 'test2.txt' was not closed\n";
}
}
}
Results
The file 'test1.txt' was not opened
The file 'test2.txt' was opened