On Wed, Apr 27, 2011 at 07:19:42AM -0400, Wietse Venema wrote: > Just because a system has getpwnam_r(), that does not mean it works > like your API; and on some systems, getpwnam() does report errors > via errno (e.g. FreeBSD8), whereas the original UNIX getpwnam() > never returned for transient errors, because all reads were from > local files.
Indeed the history of getpwnam_r() is not necessarily conformant with the POSIX spec: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpwnam.html which specifies authoritative "not found" as a non-error, and other not-found conditions as errors. For example, SunOS 5.8: SYNOPSIS #include <pwd.h> struct passwd *getpwnam(const char *name); struct passwd *getpwnam_r(const char *name, struct passwd *pwd, char *buffer, int buflen); [...] POSIX cc [ flag...] file... -D_POSIX_PTHREAD_SEMANTICS [ library... ] int getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); [...] Solaris 2.4 and earlier releases provided definitions of the getpwnam_r() and getpwuid_r() functions as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface for these functions. Support for the Draft 6 interface is provided for compatibility only and might not be supported in future releases. New applications and libraries should use the standard-conforming interface. For POSIX.1c-conforming applications, the _POSIX_PTHREAD_SEMANTICS and _REENTRANT flags are automati- cally turned on by defining the _POSIX_C_SOURCE flag with a value >= 199506L. Naturally, SunOS maintains backwards compatibility, so the same applies to SunOS 5.10. The POSIX interface requires the _POSIX_PTHREAD_SEMANTICS flag. -- Viktor.