Is there a reason that you aren't checking the return value of close? Also, shouldn't you save the original errno here before calling close which may very well clobber errno?