On Wed, Apr 27, 2011 at 08:55:53PM -0400, Wietse Venema wrote: > Of course, I could simply mandate that people run only the latest > systems and that they always set all the flags that disable SUN, > SGI etc. default backwards compatibility (meaning it may not work > with third-party libraries that are expecting the default system > semantics).
Getting back on track though, we could enable getpwnam_r on platforms (sufficiently new, ...) where we believe it to work correctly as documented. That would include at least sufficiently recent BSD variants, plus, if not too difficult to handle in makedefs + sysdefs.h, also reasonably recent Linux glibc. Handling SunOS where the default is non-POSIX more painful, not sure whether it is worth the effort, but the relevant compiler flags could be defined just around the "#include <pwd.h>" in a getpwnam() wrapper module. The SunOS header file comments are: /* * Previous releases of Solaris, starting at 2.3, provided definitions of * various functions as specified in POSIX.1c, Draft 6. For some of these * functions, the final POSIX 1003.1c standard had a different number of * arguments and return values. * * The following segment of this header provides support for the standard * interfaces while supporting applications written under earlier * releases. The application defines appropriate values of the feature * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate * whether it was written to expect the Draft 6 or standard versions of * these interfaces, before including this header. This header then * provides a mapping from the source version of the interface to an * appropriate binary interface. Such mappings permit an application * to be built from libraries and objects which have mixed expectations * of the definitions of these functions. * * For applications using the Draft 6 definitions, the binary symbol is the * same as the source symbol, and no explicit mapping is needed. For the * standard interface, the function func() is mapped to the binary symbol * _posix_func(). The preferred mechanism for the remapping is a compiler * #pragma. If the compiler does not provide such a #pragma, the header file * defines a static function func() which calls the _posix_func() version; * this has to be done instead of #define since POSIX specifies that an * application can #undef the symbol and still be bound to the correct * implementation. Unfortunately, the statics confuse lint so we fallback to * #define in that case. * * NOTE: Support for the Draft 6 definitions is provided for compatibility * only. New applications/libraries should use the standard definitions. */ #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \ defined(_POSIX_PTHREAD_SEMANTICS) || defined(__EXTENSIONS__) <POSIX INTERFACE> #else <NON-POSIX INTERFACE> #endif For (non-Sun) compilers that don't support "#pragma redefine_extname ...", the POSIX interface generates static wrappers: static int getpwuid_r(uid_t __uid, struct passwd *__pwd, char *__buf, int __len, struct passwd **__res) { return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res)); } static int getpwnam_r(const char *__cb, struct passwd *__pwd, char *__buf, int __len, struct passwd **__res) { return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res)); } otherise (Sun compilers) the symbol is aliased. -- Viktor.