Subject: Re: getpw*_r standards
To: Nathan J. Williams <email@example.com>
From: John Nemeth <firstname.lastname@example.org>
Date: 04/11/2005 04:20:24
On Aug 31, 12:36pm, "Nathan J. Williams" wrote:
} email@example.com (John Nemeth) writes:
} > Any POSIX gurus here? I'm wondering about standards compliance.
} > The POSIX definition of getpwnam_r is located here:
} > http://www.opengroup.org/onlinepubs/009695399/functions/getpwnam.html
} > At the above URL, there are no error codes listed that can be used to
} > indicate the entry wasn't found.
} RETURN VALUE
} The getpwnam() function shall return a pointer to a struct passwd
} with the structure as defined in <pwd.h> with a matching entry if
} found. A null pointer shall be returned if the requested entry is
} not found, or an error occurs. On error, errno shall be set to
} indicate the error.
} That second sentence says to me that "entry not found" is not an
} error, so we're wrong, and that Solaris is doing the right thing. The
} rest of the standards text seems to back up that idea - the bit about
} having to set errno in advance if you want to check for an error is
} key, since it indicates that returning-NULL-but-not-setting-errno is
} valid behavior.
Is errno defined in such a way that it is a per thread variable,
or is the concept of errno obselete in a threaded world? Most (all?)
of the NetBSD userland isn't threaded, but I believe the *_r functions
were invented to make things work in a threaded world.
getpwnam() doesn't have a return code. It returns a pointer to
struct passwd, so the only thing it can do is return NULL and set
errno. On the other hand, getpwnam_r() does have an explicit return
code (the pointer to struct passwd is a parameter).
}-- End of excerpt from "Nathan J. Williams"