should say ret = errno before lderr, and return ret afterwards, since printing may set errno to another value