Description of problem: sgetsgent_r does not set errno to ERANGE but returns it directly. However sgetsgent (and I suppose other eventual callers as well) expect it to set the errno to the actual error). The attached patch fixes the problem.