avoid reading errno repeatedly