fixes bad semantics (an invalid fd is -1 not 0).