Shouldn't we also be checking errno for ERANGE here?