Ensure that fileno() returns -1 when given an invalid file pointer.
Merge pull request #2157 from rfk/rfk/fileno-error-reporting

Ensure that fileno() returns -1 when given an invalid file pointer.