Is there a reason you clobber errno and don't save/propagate it back somehow?