libc: set 'errno' for invalid file descriptors

Fixes #877.