117ca54c3Smrg/* 217ca54c3SmrgCopyright 1996, 1998 The Open Group 317ca54c3Smrg 417ca54c3SmrgPermission to use, copy, modify, distribute, and sell this software and its 517ca54c3Smrgdocumentation for any purpose is hereby granted without fee, provided that 617ca54c3Smrgthe above copyright notice appear in all copies and that both that 717ca54c3Smrgcopyright notice and this permission notice appear in supporting 817ca54c3Smrgdocumentation. 917ca54c3Smrg 1017ca54c3SmrgThe above copyright notice and this permission notice shall be included in 1117ca54c3Smrgall copies or substantial portions of the Software. 1217ca54c3Smrg 1317ca54c3SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1417ca54c3SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1517ca54c3SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1617ca54c3SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1717ca54c3SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1817ca54c3SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1917ca54c3Smrg 2017ca54c3SmrgExcept as contained in this notice, the name of The Open Group shall not be 2117ca54c3Smrgused in advertising or otherwise to promote the sale, use or other dealings 2217ca54c3Smrgin this Software without prior written authorization from The Open Group. 2317ca54c3Smrg*/ 2417ca54c3Smrg 2517ca54c3Smrg/* 2617ca54c3Smrg * Various and sundry Thread-Safe functions used by X11, Motif, and CDE. 2717ca54c3Smrg * 2817ca54c3Smrg * Use this file in MT-safe code where you would have included 2917ca54c3Smrg * <dirent.h> for readdir() 3017ca54c3Smrg * <grp.h> for getgrgid() or getgrnam() 3117ca54c3Smrg * <netdb.h> for gethostbyname(), gethostbyaddr(), or getservbyname() 3217ca54c3Smrg * <pwd.h> for getpwnam() or getpwuid() 3317ca54c3Smrg * <string.h> for strtok() 3417ca54c3Smrg * <time.h> for asctime(), ctime(), localtime(), or gmtime() 3517ca54c3Smrg * <unistd.h> for getlogin() or ttyname() 3617ca54c3Smrg * or their thread-safe analogs. 3717ca54c3Smrg * 3817ca54c3Smrg * If you are on a platform that defines XTHREADS but does not have 3917ca54c3Smrg * MT-safe system API (e.g. UnixWare) you must define _Xos_processLock 4017ca54c3Smrg * and _Xos_processUnlock macros before including this header. 4117ca54c3Smrg * 4217ca54c3Smrg * For convenience XOS_USE_XLIB_LOCKING or XOS_USE_XT_LOCKING may be defined 4317ca54c3Smrg * to obtain either Xlib-only or Xt-based versions of these macros. These 4417ca54c3Smrg * macros won't result in truly thread-safe calls, but they are better than 4517ca54c3Smrg * nothing. If you do not want locking in this situation define 4617ca54c3Smrg * XOS_USE_NO_LOCKING. 4717ca54c3Smrg * 4817ca54c3Smrg * NOTE: On systems lacking appropriate _r functions Gethostbyname(), 4917ca54c3Smrg * Gethostbyaddr(), and Getservbyname() do NOT copy the host or 5017ca54c3Smrg * protocol lists! 5117ca54c3Smrg * 5217ca54c3Smrg * NOTE: On systems lacking appropriate _r functions Getgrgid() and 5317ca54c3Smrg * Getgrnam() do NOT copy the list of group members! 5417ca54c3Smrg * 5517ca54c3Smrg * This header is nominally intended to simplify porting X11, Motif, and 5617ca54c3Smrg * CDE; it may be useful to other people too. The structure below is 5717ca54c3Smrg * complicated, mostly because P1003.1c (the IEEE POSIX Threads spec) 5817ca54c3Smrg * went through lots of drafts, and some vendors shipped systems based 5917ca54c3Smrg * on draft API that were changed later. Unfortunately POSIX did not 6017ca54c3Smrg * provide a feature-test macro for distinguishing each of the drafts. 6117ca54c3Smrg */ 6217ca54c3Smrg 6317ca54c3Smrg/* 6417ca54c3Smrg * This header has several parts. Search for "Effective prototypes" 6517ca54c3Smrg * to locate the beginning of a section. 6617ca54c3Smrg */ 6717ca54c3Smrg 6817ca54c3Smrg/* This header can be included multiple times with different defines! */ 6917ca54c3Smrg#ifndef _XOS_R_H_ 7017ca54c3Smrg# define _XOS_R_H_ 7117ca54c3Smrg 7217ca54c3Smrg# include <X11/Xos.h> 7317ca54c3Smrg# include <X11/Xfuncs.h> 7417ca54c3Smrg 7517ca54c3Smrg# ifndef X_NOT_POSIX 7617ca54c3Smrg# ifdef _POSIX_SOURCE 7717ca54c3Smrg# include <limits.h> 7817ca54c3Smrg# else 7917ca54c3Smrg# define _POSIX_SOURCE 8017ca54c3Smrg# include <limits.h> 8117ca54c3Smrg# undef _POSIX_SOURCE 8217ca54c3Smrg# endif 8317ca54c3Smrg# ifndef LINE_MAX 8417ca54c3Smrg# define X_LINE_MAX 2048 8517ca54c3Smrg# else 8617ca54c3Smrg# define X_LINE_MAX LINE_MAX 8717ca54c3Smrg# endif 8817ca54c3Smrg# endif 8917ca54c3Smrg#endif /* _XOS_R_H */ 9017ca54c3Smrg 9117ca54c3Smrg#ifndef WIN32 9217ca54c3Smrg 9317ca54c3Smrg#ifdef __cplusplus 9417ca54c3Smrgextern "C" { 9517ca54c3Smrg#endif 9617ca54c3Smrg 9717ca54c3Smrg# if defined(XOS_USE_XLIB_LOCKING) 9817ca54c3Smrg# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 9917ca54c3Smrgtypedef struct _LockInfoRec *LockInfoPtr; 10017ca54c3Smrgextern LockInfoPtr _Xglobal_lock; 10117ca54c3Smrg# endif 10217ca54c3Smrg# ifndef _Xos_isThreadInitialized 10317ca54c3Smrg# define _Xos_isThreadInitialized (_Xglobal_lock) 10417ca54c3Smrg# endif 10517ca54c3Smrg# if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 10617ca54c3Smrg# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 10717ca54c3Smrg# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 10817ca54c3Smrgextern void (*_XLockMutex_fn)( 10917ca54c3Smrg# if NeedFunctionPrototypes 11017ca54c3Smrg LockInfoPtr /* lock */, char * /* file */, int /* line */ 11117ca54c3Smrg# endif 11217ca54c3Smrg); 11317ca54c3Smrgextern void (*_XUnlockMutex_fn)( 11417ca54c3Smrg# if NeedFunctionPrototypes 11517ca54c3Smrg LockInfoPtr /* lock */, char * /* file */, int /* line */ 11617ca54c3Smrg# endif 11717ca54c3Smrg); 11817ca54c3Smrg# endif 11917ca54c3Smrg# ifndef _Xos_processLock 12017ca54c3Smrg# define _Xos_processLock \ 12117ca54c3Smrg (_XLockMutex_fn ? (*_XLockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0) 12217ca54c3Smrg# endif 12317ca54c3Smrg# ifndef _Xos_processUnlock 12417ca54c3Smrg# define _Xos_processUnlock \ 12517ca54c3Smrg (_XUnlockMutex_fn ? (*_XUnlockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0) 12617ca54c3Smrg# endif 12717ca54c3Smrg# else 12817ca54c3Smrg# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 12917ca54c3Smrg# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 13017ca54c3Smrgextern void (*_XLockMutex_fn)( 13117ca54c3Smrg# if NeedFunctionPrototypes 13217ca54c3Smrg LockInfoPtr /* lock */ 13317ca54c3Smrg# endif 13417ca54c3Smrg); 13517ca54c3Smrgextern void (*_XUnlockMutex_fn)( 13617ca54c3Smrg# if NeedFunctionPrototypes 13717ca54c3Smrg LockInfoPtr /* lock */ 13817ca54c3Smrg# endif 13917ca54c3Smrg); 14017ca54c3Smrg# endif 14117ca54c3Smrg# ifndef _Xos_processLock 14217ca54c3Smrg# define _Xos_processLock \ 14317ca54c3Smrg (_XLockMutex_fn ? ((*_XLockMutex_fn)(_Xglobal_lock), 0) : 0) 14417ca54c3Smrg# endif 14517ca54c3Smrg# ifndef _Xos_processUnlock 14617ca54c3Smrg# define _Xos_processUnlock \ 14717ca54c3Smrg (_XUnlockMutex_fn ? ((*_XUnlockMutex_fn)(_Xglobal_lock), 0) : 0) 14817ca54c3Smrg# endif 14917ca54c3Smrg# endif 15017ca54c3Smrg# elif defined(XOS_USE_XT_LOCKING) 15117ca54c3Smrg# ifndef _XtThreadsI_h 15217ca54c3Smrgextern void (*_XtProcessLock)(void); 15317ca54c3Smrg# endif 15417ca54c3Smrg# ifndef _XtintrinsicP_h 15517ca54c3Smrg# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 15617ca54c3Smrgextern void XtProcessLock( 15717ca54c3Smrg# if NeedFunctionPrototypes 15817ca54c3Smrg void 15917ca54c3Smrg# endif 16017ca54c3Smrg); 16117ca54c3Smrgextern void XtProcessUnlock( 16217ca54c3Smrg# if NeedFunctionPrototypes 16317ca54c3Smrg void 16417ca54c3Smrg# endif 16517ca54c3Smrg); 16617ca54c3Smrg# endif 16717ca54c3Smrg# ifndef _Xos_isThreadInitialized 16817ca54c3Smrg# define _Xos_isThreadInitialized _XtProcessLock 16917ca54c3Smrg# endif 17017ca54c3Smrg# ifndef _Xos_processLock 17117ca54c3Smrg# define _Xos_processLock XtProcessLock() 17217ca54c3Smrg# endif 17317ca54c3Smrg# ifndef _Xos_processUnlock 17417ca54c3Smrg# define _Xos_processUnlock XtProcessUnlock() 17517ca54c3Smrg# endif 17617ca54c3Smrg# elif defined(XOS_USE_NO_LOCKING) 17717ca54c3Smrg# ifndef _Xos_isThreadInitialized 17817ca54c3Smrg# define _Xos_isThreadInitialized 0 17917ca54c3Smrg# endif 18017ca54c3Smrg# ifndef _Xos_processLock 18117ca54c3Smrg# define _Xos_processLock 0 18217ca54c3Smrg# endif 18317ca54c3Smrg# ifndef _Xos_processUnlock 18417ca54c3Smrg# define _Xos_processUnlock 0 18517ca54c3Smrg# endif 18617ca54c3Smrg# endif 18717ca54c3Smrg 18817ca54c3Smrg#endif /* !defined WIN32 */ 18917ca54c3Smrg 19017ca54c3Smrg/* 19117ca54c3Smrg * Solaris defines the POSIX thread-safe feature test macro, but 19217ca54c3Smrg * uses the older SVR4 thread-safe functions unless the POSIX ones 19317ca54c3Smrg * are specifically requested. Fix the feature test macro. 19417ca54c3Smrg */ 19517ca54c3Smrg#if defined(__sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && \ 19617ca54c3Smrg (_POSIX_C_SOURCE - 0 < 199506L) && !defined(_POSIX_PTHREAD_SEMANTICS) 19717ca54c3Smrg# undef _POSIX_THREAD_SAFE_FUNCTIONS 19817ca54c3Smrg#endif 19917ca54c3Smrg 20017ca54c3Smrg/***** <pwd.h> wrappers *****/ 20117ca54c3Smrg 20217ca54c3Smrg/* 20317ca54c3Smrg * Effective prototypes for <pwd.h> wrappers: 20417ca54c3Smrg * 20517ca54c3Smrg * #define X_INCLUDE_PWD_H 20617ca54c3Smrg * #define XOS_USE_..._LOCKING 20717ca54c3Smrg * #include <X11/Xos_r.h> 20817ca54c3Smrg * 20917ca54c3Smrg * typedef ... _Xgetpwparams; 21017ca54c3Smrg * 21117ca54c3Smrg * struct passwd* _XGetpwnam(const char *name, _Xgetpwparams); 21217ca54c3Smrg * struct passwd* _XGetpwuid(uid_t uid, _Xgetpwparams); 21317ca54c3Smrg */ 21417ca54c3Smrg 21517ca54c3Smrg#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H) 21617ca54c3Smrg# include <pwd.h> 21717ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI) 21817ca54c3Smrg# define XOS_USE_MTSAFE_PWDAPI 1 21917ca54c3Smrg# endif 22017ca54c3Smrg#endif 22117ca54c3Smrg 22217ca54c3Smrg#undef X_NEEDS_PWPARAMS 22317ca54c3Smrg#if !defined(X_INCLUDE_PWD_H) || defined(_XOS_INCLUDED_PWD_H) 22417ca54c3Smrg/* Do nothing */ 22517ca54c3Smrg 22617ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 22717ca54c3Smrg/* Use regular, unsafe API. */ 22817ca54c3Smrg# if defined(X_NOT_POSIX) && !defined(__i386__) && !defined(SYSV) 22917ca54c3Smrgextern struct passwd *getpwuid(), *getpwnam(); 23017ca54c3Smrg# endif 23117ca54c3Smrgtypedef int _Xgetpwparams; /* dummy */ 23217ca54c3Smrg# define _XGetpwuid(u,p) getpwuid((u)) 23317ca54c3Smrg# define _XGetpwnam(u,p) getpwnam((u)) 23417ca54c3Smrg 23517ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_PWDAPI) || defined(XNO_MTSAFE_PWDAPI) 23617ca54c3Smrg/* UnixWare 2.0, or other systems with thread support but no _r API. */ 23717ca54c3Smrg# define X_NEEDS_PWPARAMS 23817ca54c3Smrgtypedef struct { 23917ca54c3Smrg struct passwd pws; 24017ca54c3Smrg char pwbuf[1024]; 24117ca54c3Smrg struct passwd* pwp; 24217ca54c3Smrg size_t len; 24317ca54c3Smrg} _Xgetpwparams; 24417ca54c3Smrg 24517ca54c3Smrg/* 24617ca54c3Smrg * NetBSD and FreeBSD, at least, are missing several of the unixware passwd 24717ca54c3Smrg * fields. 24817ca54c3Smrg */ 24917ca54c3Smrg 25017ca54c3Smrg#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 25117ca54c3Smrg defined(__APPLE__) || defined(__DragonFly__) 25217ca54c3Smrgstatic __inline__ void _Xpw_copyPasswd(_Xgetpwparams p) 25317ca54c3Smrg{ 25417ca54c3Smrg memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)); 25517ca54c3Smrg 25617ca54c3Smrg (p).pws.pw_name = (p).pwbuf; 25717ca54c3Smrg (p).len = strlen((p).pwp->pw_name); 25817ca54c3Smrg strcpy((p).pws.pw_name, (p).pwp->pw_name); 25917ca54c3Smrg 26017ca54c3Smrg (p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1; 26117ca54c3Smrg (p).len = strlen((p).pwp->pw_passwd); 26217ca54c3Smrg strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd); 26317ca54c3Smrg 26417ca54c3Smrg (p).pws.pw_class = (p).pws.pw_passwd + (p).len + 1; 26517ca54c3Smrg (p).len = strlen((p).pwp->pw_class); 26617ca54c3Smrg strcpy((p).pws.pw_class, (p).pwp->pw_class); 26717ca54c3Smrg 26817ca54c3Smrg (p).pws.pw_gecos = (p).pws.pw_class + (p).len + 1; 26917ca54c3Smrg (p).len = strlen((p).pwp->pw_gecos); 27017ca54c3Smrg strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos); 27117ca54c3Smrg 27217ca54c3Smrg (p).pws.pw_dir = (p).pws.pw_gecos + (p).len + 1; 27317ca54c3Smrg (p).len = strlen((p).pwp->pw_dir); 27417ca54c3Smrg strcpy((p).pws.pw_dir, (p).pwp->pw_dir); 27517ca54c3Smrg 27617ca54c3Smrg (p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1; 27717ca54c3Smrg (p).len = strlen((p).pwp->pw_shell); 27817ca54c3Smrg strcpy((p).pws.pw_shell, (p).pwp->pw_shell); 27917ca54c3Smrg 28017ca54c3Smrg (p).pwp = &(p).pws; 28117ca54c3Smrg} 28217ca54c3Smrg 28317ca54c3Smrg#else 28417ca54c3Smrg# define _Xpw_copyPasswd(p) \ 28517ca54c3Smrg (memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)), \ 28617ca54c3Smrg ((p).pws.pw_name = (p).pwbuf), \ 28717ca54c3Smrg ((p).len = strlen((p).pwp->pw_name)), \ 28817ca54c3Smrg strcpy((p).pws.pw_name, (p).pwp->pw_name), \ 28917ca54c3Smrg ((p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1), \ 29017ca54c3Smrg ((p).len = strlen((p).pwp->pw_passwd)), \ 29117ca54c3Smrg strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd), \ 29217ca54c3Smrg ((p).pws.pw_age = (p).pws.pw_passwd + (p).len + 1), \ 29317ca54c3Smrg ((p).len = strlen((p).pwp->pw_age)), \ 29417ca54c3Smrg strcpy((p).pws.pw_age, (p).pwp->pw_age), \ 29517ca54c3Smrg ((p).pws.pw_comment = (p).pws.pw_age + (p).len + 1), \ 29617ca54c3Smrg ((p).len = strlen((p).pwp->pw_comment)), \ 29717ca54c3Smrg strcpy((p).pws.pw_comment, (p).pwp->pw_comment), \ 29817ca54c3Smrg ((p).pws.pw_gecos = (p).pws.pw_comment + (p).len + 1), \ 29917ca54c3Smrg ((p).len = strlen((p).pwp->pw_gecos)), \ 30017ca54c3Smrg strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos), \ 30117ca54c3Smrg ((p).pws.pw_dir = (p).pws.pw_comment + (p).len + 1), \ 30217ca54c3Smrg ((p).len = strlen((p).pwp->pw_dir)), \ 30317ca54c3Smrg strcpy((p).pws.pw_dir, (p).pwp->pw_dir), \ 30417ca54c3Smrg ((p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1), \ 30517ca54c3Smrg ((p).len = strlen((p).pwp->pw_shell)), \ 30617ca54c3Smrg strcpy((p).pws.pw_shell, (p).pwp->pw_shell), \ 30717ca54c3Smrg ((p).pwp = &(p).pws), \ 30817ca54c3Smrg 0 ) 30917ca54c3Smrg#endif 31017ca54c3Smrg# define _XGetpwuid(u,p) \ 31117ca54c3Smrg( (_Xos_processLock), \ 31217ca54c3Smrg (((p).pwp = getpwuid((u))) ? _Xpw_copyPasswd(p), 0 : 0), \ 31317ca54c3Smrg (_Xos_processUnlock), \ 31417ca54c3Smrg (p).pwp ) 31517ca54c3Smrg# define _XGetpwnam(u,p) \ 31617ca54c3Smrg( (_Xos_processLock), \ 31717ca54c3Smrg (((p).pwp = getpwnam((u))) ? _Xpw_copyPasswd(p), 0 : 0), \ 31817ca54c3Smrg (_Xos_processUnlock), \ 31917ca54c3Smrg (p).pwp ) 32017ca54c3Smrg 32117ca54c3Smrg#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__) 32217ca54c3Smrg# define X_NEEDS_PWPARAMS 32317ca54c3Smrgtypedef struct { 32417ca54c3Smrg struct passwd pws; 32517ca54c3Smrg char pwbuf[X_LINE_MAX]; 32617ca54c3Smrg} _Xgetpwparams; 32717ca54c3Smrg# if defined(_POSIX_REENTRANT_FUNCTIONS) || !defined(SVR4) 32817ca54c3Smrg# define _XGetpwuid(u,p) \ 32917ca54c3Smrg((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 33017ca54c3Smrg# define _XGetpwnam(u,p) \ 33117ca54c3Smrg((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 33217ca54c3Smrg# else /* SVR4 */ 33317ca54c3Smrg# define _XGetpwuid(u,p) \ 33417ca54c3Smrg((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws) 33517ca54c3Smrg# define _XGetpwnam(u,p) \ 33617ca54c3Smrg((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws) 33717ca54c3Smrg# endif /* SVR4 */ 33817ca54c3Smrg 33917ca54c3Smrg#else /* _POSIX_THREAD_SAFE_FUNCTIONS */ 34017ca54c3Smrg# define X_NEEDS_PWPARAMS 34117ca54c3Smrgtypedef struct { 34217ca54c3Smrg struct passwd pws; 34317ca54c3Smrg char pwbuf[X_LINE_MAX]; 34417ca54c3Smrg struct passwd* pwp; 34517ca54c3Smrg} _Xgetpwparams; 34617ca54c3Smrgtypedef int _Xgetpwret; 34717ca54c3Smrg# define _XGetpwuid(u,p) \ 34817ca54c3Smrg((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == 0) ? \ 34917ca54c3Smrg (p).pwp : NULL) 35017ca54c3Smrg# define _XGetpwnam(u,p) \ 35117ca54c3Smrg((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == 0) ? \ 35217ca54c3Smrg (p).pwp : NULL) 35317ca54c3Smrg#endif /* X_INCLUDE_PWD_H */ 35417ca54c3Smrg 35517ca54c3Smrg#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H) 35617ca54c3Smrg# define _XOS_INCLUDED_PWD_H 35717ca54c3Smrg#endif 35817ca54c3Smrg 35917ca54c3Smrg 36017ca54c3Smrg/***** <netdb.h> wrappers *****/ 36117ca54c3Smrg 36217ca54c3Smrg/* 36317ca54c3Smrg * Effective prototypes for <netdb.h> wrappers: 36417ca54c3Smrg * 36517ca54c3Smrg * NOTE: On systems lacking the appropriate _r functions Gethostbyname(), 36617ca54c3Smrg * Gethostbyaddr(), and Getservbyname() do NOT copy the host or 36717ca54c3Smrg * protocol lists! 36817ca54c3Smrg * 36917ca54c3Smrg * #define X_INCLUDE_NETDB_H 37017ca54c3Smrg * #define XOS_USE_..._LOCKING 37117ca54c3Smrg * #include <X11/Xos_r.h> 37217ca54c3Smrg * 37317ca54c3Smrg * typedef ... _Xgethostbynameparams; 37417ca54c3Smrg * typedef ... _Xgetservbynameparams; 37517ca54c3Smrg * 37617ca54c3Smrg * struct hostent* _XGethostbyname(const char* name,_Xgethostbynameparams); 37717ca54c3Smrg * struct hostent* _XGethostbyaddr(const char* addr, int len, int type, 37817ca54c3Smrg * _Xgethostbynameparams); 37917ca54c3Smrg * struct servent* _XGetservbyname(const char* name, const char* proto, 38017ca54c3Smrg * _Xgetservbynameparams); 38117ca54c3Smrg */ 38217ca54c3Smrg 38317ca54c3Smrg#undef XTHREADS_NEEDS_BYNAMEPARAMS 38417ca54c3Smrg#if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \ 38517ca54c3Smrg && !defined(WIN32) 38617ca54c3Smrg# include <netdb.h> 38717ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI) 38817ca54c3Smrg# define XOS_USE_MTSAFE_NETDBAPI 1 38917ca54c3Smrg# endif 39017ca54c3Smrg#endif 39117ca54c3Smrg 39217ca54c3Smrg#if !defined(X_INCLUDE_NETDB_H) || defined(_XOS_INCLUDED_NETDB_H) 39317ca54c3Smrg/* Do nothing. */ 39417ca54c3Smrg 39517ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 39617ca54c3Smrg/* Use regular, unsafe API. */ 39717ca54c3Smrgtypedef int _Xgethostbynameparams; /* dummy */ 39817ca54c3Smrgtypedef int _Xgetservbynameparams; /* dummy */ 39917ca54c3Smrg# define _XGethostbyname(h,hp) gethostbyname((h)) 40017ca54c3Smrg# define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t)) 40117ca54c3Smrg# define _XGetservbyname(s,p,sp) getservbyname((s),(p)) 40217ca54c3Smrg 40317ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_NETDBAPI) || defined(XNO_MTSAFE_NETDBAPI) 40417ca54c3Smrg/* WARNING: The h_addr_list and s_aliases values are *not* copied! */ 40517ca54c3Smrg 40617ca54c3Smrg#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) 40717ca54c3Smrg#include <sys/param.h> 40817ca54c3Smrg#endif 40917ca54c3Smrg 41017ca54c3Smrgtypedef struct { 41117ca54c3Smrg struct hostent hent; 41217ca54c3Smrg char h_name[MAXHOSTNAMELEN]; 41317ca54c3Smrg struct hostent *hptr; 41417ca54c3Smrg} _Xgethostbynameparams; 41517ca54c3Smrgtypedef struct { 41617ca54c3Smrg struct servent sent; 41717ca54c3Smrg char s_name[255]; 41817ca54c3Smrg char s_proto[255]; 41917ca54c3Smrg struct servent *sptr; 42017ca54c3Smrg} _Xgetservbynameparams; 42117ca54c3Smrg 42217ca54c3Smrg# define XTHREADS_NEEDS_BYNAMEPARAMS 42317ca54c3Smrg 42417ca54c3Smrg# define _Xg_copyHostent(hp) \ 42517ca54c3Smrg (memcpy(&(hp).hent, (hp).hptr, sizeof(struct hostent)), \ 42617ca54c3Smrg strcpy((hp).h_name, (hp).hptr->h_name), \ 42717ca54c3Smrg ((hp).hent.h_name = (hp).h_name), \ 42817ca54c3Smrg ((hp).hptr = &(hp).hent), \ 42917ca54c3Smrg 0 ) 43017ca54c3Smrg# define _Xg_copyServent(sp) \ 43117ca54c3Smrg (memcpy(&(sp).sent, (sp).sptr, sizeof(struct servent)), \ 43217ca54c3Smrg strcpy((sp).s_name, (sp).sptr->s_name), \ 43317ca54c3Smrg ((sp).sent.s_name = (sp).s_name), \ 43417ca54c3Smrg strcpy((sp).s_proto, (sp).sptr->s_proto), \ 43517ca54c3Smrg ((sp).sent.s_proto = (sp).s_proto), \ 43617ca54c3Smrg ((sp).sptr = &(sp).sent), \ 43717ca54c3Smrg 0 ) 43817ca54c3Smrg# define _XGethostbyname(h,hp) \ 43917ca54c3Smrg ((_Xos_processLock), \ 44017ca54c3Smrg (((hp).hptr = gethostbyname((h))) ? _Xg_copyHostent(hp) : 0), \ 44117ca54c3Smrg (_Xos_processUnlock), \ 44217ca54c3Smrg (hp).hptr ) 44317ca54c3Smrg# define _XGethostbyaddr(a,al,t,hp) \ 44417ca54c3Smrg ((_Xos_processLock), \ 44517ca54c3Smrg (((hp).hptr = gethostbyaddr((a),(al),(t))) ? _Xg_copyHostent(hp) : 0), \ 44617ca54c3Smrg (_Xos_processUnlock), \ 44717ca54c3Smrg (hp).hptr ) 44817ca54c3Smrg# define _XGetservbyname(s,p,sp) \ 44917ca54c3Smrg ((_Xos_processLock), \ 45017ca54c3Smrg (((sp).sptr = getservbyname((s),(p))) ? _Xg_copyServent(sp) : 0), \ 45117ca54c3Smrg (_Xos_processUnlock), \ 45217ca54c3Smrg (sp).sptr ) 45317ca54c3Smrg 45417ca54c3Smrg#elif defined(XUSE_NETDB_R_API) 45517ca54c3Smrg/* 45617ca54c3Smrg * POSIX does not specify _r equivalents for <netdb.h> API, but some 45717ca54c3Smrg * vendors provide them anyway. Use them only when explicitly asked. 45817ca54c3Smrg */ 45917ca54c3Smrg# ifdef _POSIX_REENTRANT_FUNCTIONS 46017ca54c3Smrg# ifndef _POSIX_THREAD_SAFE_FUNCTIONS 46117ca54c3Smrg# endif 46217ca54c3Smrg# endif 46317ca54c3Smrg# ifdef _POSIX_THREAD_SAFE_FUNCTIONS 46417ca54c3Smrg# define X_POSIX_THREAD_SAFE_FUNCTIONS 1 46517ca54c3Smrg# endif 46617ca54c3Smrg 46717ca54c3Smrg# define XTHREADS_NEEDS_BYNAMEPARAMS 46817ca54c3Smrg 46917ca54c3Smrg# ifndef X_POSIX_THREAD_SAFE_FUNCTIONS 47017ca54c3Smrgtypedef struct { 47117ca54c3Smrg struct hostent hent; 47217ca54c3Smrg char hbuf[X_LINE_MAX]; 47317ca54c3Smrg int herr; 47417ca54c3Smrg} _Xgethostbynameparams; 47517ca54c3Smrgtypedef struct { 47617ca54c3Smrg struct servent sent; 47717ca54c3Smrg char sbuf[X_LINE_MAX]; 47817ca54c3Smrg} _Xgetservbynameparams; 47917ca54c3Smrg# define _XGethostbyname(h,hp) \ 48017ca54c3Smrg gethostbyname_r((h),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr) 48117ca54c3Smrg# define _XGethostbyaddr(a,al,t,hp) \ 48217ca54c3Smrg gethostbyaddr_r((a),(al),(t),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr) 48317ca54c3Smrg# define _XGetservbyname(s,p,sp) \ 48417ca54c3Smrg getservbyname_r((s),(p),&(sp).sent,(sp).sbuf,sizeof((sp).sbuf)) 48517ca54c3Smrg# else 48617ca54c3Smrgtypedef struct { 48717ca54c3Smrg struct hostent hent; 48817ca54c3Smrg struct hostent_data hdata; 48917ca54c3Smrg} _Xgethostbynameparams; 49017ca54c3Smrgtypedef struct { 49117ca54c3Smrg struct servent sent; 49217ca54c3Smrg struct servent_data sdata; 49317ca54c3Smrg} _Xgetservbynameparams; 49417ca54c3Smrg# define _XGethostbyname(h,hp) \ 49517ca54c3Smrg (bzero((char*)&(hp).hdata,sizeof((hp).hdata)), \ 49617ca54c3Smrg ((gethostbyname_r((h),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent)) 49717ca54c3Smrg# define _XGethostbyaddr(a,al,t,hp) \ 49817ca54c3Smrg (bzero((char*)&(hp).hdata,sizeof((hp).hdata)), \ 49917ca54c3Smrg ((gethostbyaddr_r((a),(al),(t),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent)) 50017ca54c3Smrg# define _XGetservbyname(s,p,sp) \ 50117ca54c3Smrg (bzero((char*)&(sp).sdata,sizeof((sp).sdata)), \ 50217ca54c3Smrg ((getservbyname_r((s),(p),&(sp).sent,&(sp).sdata) == -1) ? NULL : &(sp).sent) ) 50317ca54c3Smrg# endif 50417ca54c3Smrg# ifdef X_POSIX_THREAD_SAFE_FUNCTIONS 50517ca54c3Smrg# undef X_POSIX_THREAD_SAFE_FUNCTIONS 50617ca54c3Smrg# endif 50717ca54c3Smrg 50817ca54c3Smrg#else 50917ca54c3Smrg/* The regular API is assumed to be MT-safe under POSIX. */ 51017ca54c3Smrgtypedef int _Xgethostbynameparams; /* dummy */ 51117ca54c3Smrgtypedef int _Xgetservbynameparams; /* dummy */ 51217ca54c3Smrg# define _XGethostbyname(h,hp) gethostbyname((h)) 51317ca54c3Smrg# define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t)) 51417ca54c3Smrg# define _XGetservbyname(s,p,sp) getservbyname((s),(p)) 51517ca54c3Smrg#endif /* X_INCLUDE_NETDB_H */ 51617ca54c3Smrg 51717ca54c3Smrg#if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) 51817ca54c3Smrg# define _XOS_INCLUDED_NETDB_H 51917ca54c3Smrg#endif 52017ca54c3Smrg 52117ca54c3Smrg 52217ca54c3Smrg/***** <dirent.h> wrappers *****/ 52317ca54c3Smrg 52417ca54c3Smrg/* 52517ca54c3Smrg * Effective prototypes for <dirent.h> wrappers: 52617ca54c3Smrg * 52717ca54c3Smrg * #define X_INCLUDE_DIRENT_H 52817ca54c3Smrg * #define XOS_USE_..._LOCKING 52917ca54c3Smrg * #include <X11/Xos_r.h> 53017ca54c3Smrg * 53117ca54c3Smrg * typedef ... _Xreaddirparams; 53217ca54c3Smrg * 53317ca54c3Smrg * struct dirent *_XReaddir(DIR *dir_pointer, _Xreaddirparams); 53417ca54c3Smrg */ 53517ca54c3Smrg 53617ca54c3Smrg#if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H) 53717ca54c3Smrg# include <sys/types.h> 53817ca54c3Smrg# if !defined(X_NOT_POSIX) || defined(SYSV) 53917ca54c3Smrg# include <dirent.h> 54017ca54c3Smrg# else 54117ca54c3Smrg# include <sys/dir.h> 54217ca54c3Smrg# ifndef dirent 54317ca54c3Smrg# define dirent direct 54417ca54c3Smrg# endif 54517ca54c3Smrg# endif 54617ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_DIRENTAPI) 54717ca54c3Smrg# define XOS_USE_MTSAFE_DIRENTAPI 1 54817ca54c3Smrg# endif 54917ca54c3Smrg#endif 55017ca54c3Smrg 55117ca54c3Smrg#if !defined(X_INCLUDE_DIRENT_H) || defined(_XOS_INCLUDED_DIRENT_H) 55217ca54c3Smrg/* Do nothing. */ 55317ca54c3Smrg 55417ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 55517ca54c3Smrg/* Use regular, unsafe API. */ 55617ca54c3Smrgtypedef int _Xreaddirparams; /* dummy */ 55717ca54c3Smrg# define _XReaddir(d,p) readdir(d) 55817ca54c3Smrg 55917ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_DIRENTAPI) || defined(XNO_MTSAFE_DIRENTAPI) 56017ca54c3Smrg/* Systems with thread support but no _r API. */ 56117ca54c3Smrgtypedef struct { 56217ca54c3Smrg struct dirent *result; 56317ca54c3Smrg struct dirent dir_entry; 56417ca54c3Smrg# ifdef _POSIX_PATH_MAX 56517ca54c3Smrg char buf[_POSIX_PATH_MAX]; 56617ca54c3Smrg# elif defined(NAME_MAX) 56717ca54c3Smrg char buf[NAME_MAX]; 56817ca54c3Smrg# else 56917ca54c3Smrg char buf[255]; 57017ca54c3Smrg# endif 57117ca54c3Smrg} _Xreaddirparams; 57217ca54c3Smrg 57317ca54c3Smrg# define _XReaddir(d,p) \ 57417ca54c3Smrg ( (_Xos_processLock), \ 57517ca54c3Smrg (((p).result = readdir((d))) ? \ 57617ca54c3Smrg (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \ 57717ca54c3Smrg ((p).result = &(p).dir_entry), 0) : \ 57817ca54c3Smrg 0), \ 57917ca54c3Smrg (_Xos_processUnlock), \ 58017ca54c3Smrg (p).result ) 58117ca54c3Smrg 58217ca54c3Smrg#else 58317ca54c3Smrgtypedef struct { 58417ca54c3Smrg struct dirent *result; 58517ca54c3Smrg struct dirent dir_entry; 58617ca54c3Smrg# ifdef _POSIX_PATH_MAX 58717ca54c3Smrg char buf[_POSIX_PATH_MAX]; 58817ca54c3Smrg# elif defined(NAME_MAX) 58917ca54c3Smrg char buf[NAME_MAX]; 59017ca54c3Smrg# else 59117ca54c3Smrg char buf[255]; 59217ca54c3Smrg# endif 59317ca54c3Smrg} _Xreaddirparams; 59417ca54c3Smrg 59517ca54c3Smrg# if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__APPLE__) 59617ca54c3Smrg/* POSIX final API, returns (int)0 on success. */ 59717ca54c3Smrg# define _XReaddir(d,p) \ 59817ca54c3Smrg (readdir_r((d), &((p).dir_entry), &((p).result)) ? NULL : (p).result) 59917ca54c3Smrg# elif defined(_POSIX_REENTRANT_FUNCTIONS) 60017ca54c3Smrg/* POSIX draft API, returns (int)0 on success. */ 60117ca54c3Smrg# define _XReaddir(d,p) \ 60217ca54c3Smrg (readdir_r((d),&((p).dir_entry)) ? NULL : &((p).dir_entry)) 60317ca54c3Smrg# elif defined(SVR4) 60417ca54c3Smrg/* Pre-POSIX API, returns non-NULL on success. */ 60517ca54c3Smrg# define _XReaddir(d,p) (readdir_r((d), &(p).dir_entry)) 60617ca54c3Smrg# else 60717ca54c3Smrg/* We have no idea what is going on. Fake it all using process locks. */ 60817ca54c3Smrg# define _XReaddir(d,p) \ 60917ca54c3Smrg ( (_Xos_processLock), \ 61017ca54c3Smrg (((p).result = readdir((d))) ? \ 61117ca54c3Smrg (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \ 61217ca54c3Smrg ((p).result = &(p).dir_entry), 0) : \ 61317ca54c3Smrg 0), \ 61417ca54c3Smrg (_Xos_processUnlock), \ 61517ca54c3Smrg (p).result ) 61617ca54c3Smrg# endif 61717ca54c3Smrg#endif /* X_INCLUDE_DIRENT_H */ 61817ca54c3Smrg 61917ca54c3Smrg#if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H) 62017ca54c3Smrg# define _XOS_INCLUDED_DIRENT_H 62117ca54c3Smrg#endif 62217ca54c3Smrg 62317ca54c3Smrg 62417ca54c3Smrg/***** <unistd.h> wrappers *****/ 62517ca54c3Smrg 62617ca54c3Smrg/* 62717ca54c3Smrg * Effective prototypes for <unistd.h> wrappers: 62817ca54c3Smrg * 62917ca54c3Smrg * #define X_INCLUDE_UNISTD_H 63017ca54c3Smrg * #define XOS_USE_..._LOCKING 63117ca54c3Smrg * #include <X11/Xos_r.h> 63217ca54c3Smrg * 63317ca54c3Smrg * typedef ... _Xgetloginparams; 63417ca54c3Smrg * typedef ... _Xttynameparams; 63517ca54c3Smrg * 63617ca54c3Smrg * char *_XGetlogin(_Xgetloginparams); 63717ca54c3Smrg * char *_XTtyname(int, _Xttynameparams); 63817ca54c3Smrg */ 63917ca54c3Smrg 64017ca54c3Smrg#if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H) 64117ca54c3Smrg/* <unistd.h> already included by <X11/Xos.h> */ 64217ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_UNISTDAPI) 64317ca54c3Smrg# define XOS_USE_MTSAFE_UNISTDAPI 1 64417ca54c3Smrg# endif 64517ca54c3Smrg#endif 64617ca54c3Smrg 64717ca54c3Smrg#if !defined(X_INCLUDE_UNISTD_H) || defined(_XOS_INCLUDED_UNISTD_H) 64817ca54c3Smrg/* Do nothing. */ 64917ca54c3Smrg 65017ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 65117ca54c3Smrg/* Use regular, unsafe API. */ 65217ca54c3Smrgtypedef int _Xgetloginparams; /* dummy */ 65317ca54c3Smrgtypedef int _Xttynameparams; /* dummy */ 65417ca54c3Smrg# define _XGetlogin(p) getlogin() 65517ca54c3Smrg# define _XTtyname(f) ttyname((f)) 65617ca54c3Smrg 65717ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_UNISTDAPI) || defined(XNO_MTSAFE_UNISTDAPI) 65817ca54c3Smrg/* Systems with thread support but no _r API. */ 65917ca54c3Smrgtypedef struct { 66017ca54c3Smrg char *result; 66117ca54c3Smrg# if defined(MAXLOGNAME) 66217ca54c3Smrg char buf[MAXLOGNAME]; 66317ca54c3Smrg# elif defined(LOGIN_NAME_MAX) 66417ca54c3Smrg char buf[LOGIN_NAME_MAX]; 66517ca54c3Smrg# else 66617ca54c3Smrg char buf[64]; 66717ca54c3Smrg# endif 66817ca54c3Smrg} _Xgetloginparams; 66917ca54c3Smrgtypedef struct { 67017ca54c3Smrg char *result; 67117ca54c3Smrg# ifdef TTY_NAME_MAX 67217ca54c3Smrg char buf[TTY_NAME_MAX]; 67317ca54c3Smrg# elif defined(_POSIX_TTY_NAME_MAX) 67417ca54c3Smrg char buf[_POSIX_TTY_NAME_MAX]; 67517ca54c3Smrg# elif defined(_POSIX_PATH_MAX) 67617ca54c3Smrg char buf[_POSIX_PATH_MAX]; 67717ca54c3Smrg# else 67817ca54c3Smrg char buf[256]; 67917ca54c3Smrg# endif 68017ca54c3Smrg} _Xttynameparams; 68117ca54c3Smrg 68217ca54c3Smrg# define _XGetlogin(p) \ 68317ca54c3Smrg ( (_Xos_processLock), \ 68417ca54c3Smrg (((p).result = getlogin()) ? \ 68517ca54c3Smrg (strncpy((p).buf, (p).result, sizeof((p).buf)), \ 68617ca54c3Smrg ((p).buf[sizeof((p).buf)-1] = '\0'), \ 68717ca54c3Smrg ((p).result = (p).buf), 0) : 0), \ 68817ca54c3Smrg (_Xos_processUnlock), \ 68917ca54c3Smrg (p).result ) 69017ca54c3Smrg#define _XTtyname(f,p) \ 69117ca54c3Smrg ( (_Xos_processLock), \ 69217ca54c3Smrg (((p).result = ttyname(f)) ? \ 69317ca54c3Smrg (strncpy((p).buf, (p).result, sizeof((p).buf)), \ 69417ca54c3Smrg ((p).buf[sizeof((p).buf)-1] = '\0'), \ 69517ca54c3Smrg ((p).result = (p).buf), 0) : 0), \ 69617ca54c3Smrg (_Xos_processUnlock), \ 69717ca54c3Smrg (p).result ) 69817ca54c3Smrg 69917ca54c3Smrg#elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_POSIX_REENTRANT_FUNCTIONS) 70017ca54c3Smrg/* POSIX API. 70117ca54c3Smrg * 70217ca54c3Smrg * extern int getlogin_r(char *, size_t); 70317ca54c3Smrg * extern int ttyname_r(int, char *, size_t); 70417ca54c3Smrg */ 70517ca54c3Smrgtypedef struct { 70617ca54c3Smrg# if defined(MAXLOGNAME) 70717ca54c3Smrg char buf[MAXLOGNAME]; 70817ca54c3Smrg# elif defined(LOGIN_NAME_MAX) 70917ca54c3Smrg char buf[LOGIN_NAME_MAX]; 71017ca54c3Smrg# else 71117ca54c3Smrg char buf[64]; 71217ca54c3Smrg# endif 71317ca54c3Smrg} _Xgetloginparams; 71417ca54c3Smrgtypedef struct { 71517ca54c3Smrg# ifdef TTY_NAME_MAX 71617ca54c3Smrg char buf[TTY_NAME_MAX]; 71717ca54c3Smrg# elif defined(_POSIX_TTY_NAME_MAX) 71817ca54c3Smrg char buf[_POSIX_TTY_NAME_MAX]; 71917ca54c3Smrg# elif defined(_POSIX_PATH_MAX) 72017ca54c3Smrg char buf[_POSIX_PATH_MAX]; 72117ca54c3Smrg# else 72217ca54c3Smrg char buf[256]; 72317ca54c3Smrg# endif 72417ca54c3Smrg} _Xttynameparams; 72517ca54c3Smrg 72617ca54c3Smrg# define _XGetlogin(p) (getlogin_r((p).buf, sizeof((p).buf)) ? NULL : (p).buf) 72717ca54c3Smrg# define _XTtyname(f,p) \ 72817ca54c3Smrg (ttyname_r((f), (p).buf, sizeof((p).buf)) ? NULL : (p).buf) 72917ca54c3Smrg 73017ca54c3Smrg#else 73117ca54c3Smrg/* Pre-POSIX API. 73217ca54c3Smrg * 73317ca54c3Smrg * extern char *getlogin_r(char *, size_t); 73417ca54c3Smrg * extern char *ttyname_r(int, char *, size_t); 73517ca54c3Smrg */ 73617ca54c3Smrgtypedef struct { 73717ca54c3Smrg# if defined(MAXLOGNAME) 73817ca54c3Smrg char buf[MAXLOGNAME]; 73917ca54c3Smrg# elif defined(LOGIN_NAME_MAX) 74017ca54c3Smrg char buf[LOGIN_NAME_MAX]; 74117ca54c3Smrg# else 74217ca54c3Smrg char buf[64]; 74317ca54c3Smrg# endif 74417ca54c3Smrg} _Xgetloginparams; 74517ca54c3Smrgtypedef struct { 74617ca54c3Smrg# ifdef TTY_NAME_MAX 74717ca54c3Smrg char buf[TTY_NAME_MAX]; 74817ca54c3Smrg# elif defined(_POSIX_TTY_NAME_MAX) 74917ca54c3Smrg char buf[_POSIX_TTY_NAME_MAX]; 75017ca54c3Smrg# elif defined(_POSIX_PATH_MAX) 75117ca54c3Smrg char buf[_POSIX_PATH_MAX]; 75217ca54c3Smrg# else 75317ca54c3Smrg char buf[256]; 75417ca54c3Smrg# endif 75517ca54c3Smrg} _Xttynameparams; 75617ca54c3Smrg 75717ca54c3Smrg# define _XGetlogin(p) getlogin_r((p).buf, sizeof((p).buf)) 75817ca54c3Smrg# define _XTtyname(f,p) ttyname_r((f), (p).buf, sizeof((p).buf)) 75917ca54c3Smrg#endif /* X_INCLUDE_UNISTD_H */ 76017ca54c3Smrg 76117ca54c3Smrg#if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H) 76217ca54c3Smrg# define _XOS_INCLUDED_UNISTD_H 76317ca54c3Smrg#endif 76417ca54c3Smrg 76517ca54c3Smrg 76617ca54c3Smrg/***** <string.h> wrappers *****/ 76717ca54c3Smrg 76817ca54c3Smrg/* 76917ca54c3Smrg * Effective prototypes for <string.h> wrappers: 77017ca54c3Smrg * 77117ca54c3Smrg * #define X_INCLUDE_STRING_H 77217ca54c3Smrg * #define XOS_USE_..._LOCKING 77317ca54c3Smrg * #include <X11/Xos_r.h> 77417ca54c3Smrg * 77517ca54c3Smrg * typedef ... _Xstrtokparams; 77617ca54c3Smrg * 77717ca54c3Smrg * char *_XStrtok(char *, const char*, _Xstrtokparams); 77817ca54c3Smrg */ 77917ca54c3Smrg 78017ca54c3Smrg#if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H) 78117ca54c3Smrg/* <string.h> has already been included by <X11/Xos.h> */ 78217ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_STRINGAPI) 78317ca54c3Smrg# define XOS_USE_MTSAFE_STRINGAPI 1 78417ca54c3Smrg# endif 78517ca54c3Smrg#endif 78617ca54c3Smrg 78717ca54c3Smrg#if !defined(X_INCLUDE_STRING_H) || defined(_XOS_INCLUDED_STRING_H) 78817ca54c3Smrg/* Do nothing. */ 78917ca54c3Smrg 79017ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 79117ca54c3Smrg/* Use regular, unsafe API. */ 79217ca54c3Smrgtypedef int _Xstrtokparams; /* dummy */ 79317ca54c3Smrg# define _XStrtok(s1,s2,p) \ 79417ca54c3Smrg ( p = 0, (void)p, strtok((s1),(s2)) ) 79517ca54c3Smrg 79617ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_STRINGAPI) || defined(XNO_MTSAFE_STRINGAPI) 79717ca54c3Smrg/* Systems with thread support but no _r API. */ 79817ca54c3Smrgtypedef char *_Xstrtokparams; 79917ca54c3Smrg# define _XStrtok(s1,s2,p) \ 80017ca54c3Smrg ( (_Xos_processLock), \ 80117ca54c3Smrg ((p) = strtok((s1),(s2))), \ 80217ca54c3Smrg (_Xos_processUnlock), \ 80317ca54c3Smrg (p) ) 80417ca54c3Smrg 80517ca54c3Smrg#else 80617ca54c3Smrg/* POSIX or pre-POSIX API. */ 80717ca54c3Smrgtypedef char * _Xstrtokparams; 80817ca54c3Smrg# define _XStrtok(s1,s2,p) strtok_r((s1),(s2),&(p)) 80917ca54c3Smrg#endif /* X_INCLUDE_STRING_H */ 81017ca54c3Smrg 81117ca54c3Smrg 81217ca54c3Smrg/***** <time.h> wrappers *****/ 81317ca54c3Smrg 81417ca54c3Smrg/* 81517ca54c3Smrg * Effective prototypes for <time.h> wrappers: 81617ca54c3Smrg * 81717ca54c3Smrg * #define X_INCLUDE_TIME_H 81817ca54c3Smrg * #define XOS_USE_..._LOCKING 81917ca54c3Smrg * #include <X11/Xos_r.h> 82017ca54c3Smrg * 82117ca54c3Smrg * typedef ... _Xatimeparams; 82217ca54c3Smrg * typedef ... _Xctimeparams; 82317ca54c3Smrg * typedef ... _Xgtimeparams; 82417ca54c3Smrg * typedef ... _Xltimeparams; 82517ca54c3Smrg * 82617ca54c3Smrg * char *_XAsctime(const struct tm *, _Xatimeparams); 82717ca54c3Smrg * char *_XCtime(const time_t *, _Xctimeparams); 82817ca54c3Smrg * struct tm *_XGmtime(const time_t *, _Xgtimeparams); 82917ca54c3Smrg * struct tm *_XLocaltime(const time_t *, _Xltimeparams); 83017ca54c3Smrg */ 83117ca54c3Smrg 83217ca54c3Smrg#if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H) 83317ca54c3Smrg# include <time.h> 83417ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_TIMEAPI) 83517ca54c3Smrg# define XOS_USE_MTSAFE_TIMEAPI 1 83617ca54c3Smrg# endif 83717ca54c3Smrg#endif 83817ca54c3Smrg 83917ca54c3Smrg#if !defined(X_INCLUDE_TIME_H) || defined(_XOS_INCLUDED_TIME_H) 84017ca54c3Smrg/* Do nothing. */ 84117ca54c3Smrg 84217ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 84317ca54c3Smrg/* Use regular, unsafe API. */ 84417ca54c3Smrgtypedef int _Xatimeparams; /* dummy */ 84517ca54c3Smrg# define _XAsctime(t,p) asctime((t)) 84617ca54c3Smrgtypedef int _Xctimeparams; /* dummy */ 84717ca54c3Smrg# define _XCtime(t,p) ctime((t)) 84817ca54c3Smrgtypedef int _Xgtimeparams; /* dummy */ 84917ca54c3Smrg# define _XGmtime(t,p) gmtime((t)) 85017ca54c3Smrgtypedef int _Xltimeparams; /* dummy */ 85117ca54c3Smrg# define _XLocaltime(t,p) localtime((t)) 85217ca54c3Smrg 85317ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_TIMEAPI) || defined(XNO_MTSAFE_TIMEAPI) 85417ca54c3Smrg/* Systems with thread support but no _r API. */ 85517ca54c3Smrgtypedef struct { 85617ca54c3Smrg# ifdef TIMELEN 85717ca54c3Smrg char buf[TIMELEN]; 85817ca54c3Smrg# else 85917ca54c3Smrg char buf[26]; 86017ca54c3Smrg# endif 86117ca54c3Smrg char *result; 86217ca54c3Smrg} _Xctimeparams, _Xatimeparams; 86317ca54c3Smrgtypedef struct { 86417ca54c3Smrg struct tm buf; 86517ca54c3Smrg struct tm *result; 86617ca54c3Smrg} _Xgtimeparams, _Xltimeparams; 86717ca54c3Smrg# define _XAsctime(t,p) \ 86817ca54c3Smrg ( (_Xos_processLock), \ 86917ca54c3Smrg (((p).result = asctime((t))) ? \ 87017ca54c3Smrg (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 87117ca54c3Smrg 0), \ 87217ca54c3Smrg (_Xos_processUnlock), \ 87317ca54c3Smrg (p).result ) 87417ca54c3Smrg# define _XCtime(t,p) \ 87517ca54c3Smrg ( (_Xos_processLock), \ 87617ca54c3Smrg (((p).result = ctime((t))) ? \ 87717ca54c3Smrg (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 87817ca54c3Smrg 0), \ 87917ca54c3Smrg (_Xos_processUnlock), \ 88017ca54c3Smrg (p).result ) 88117ca54c3Smrg# define _XGmtime(t,p) \ 88217ca54c3Smrg ( (_Xos_processLock), \ 88317ca54c3Smrg (((p).result = gmtime(t)) ? \ 88417ca54c3Smrg (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 88517ca54c3Smrg 0), \ 88617ca54c3Smrg (_Xos_processUnlock), \ 88717ca54c3Smrg (p).result ) 88817ca54c3Smrg# define _XLocaltime(t,p) \ 88917ca54c3Smrg ( (_Xos_processLock), \ 89017ca54c3Smrg (((p).result = localtime(t)) ? \ 89117ca54c3Smrg (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 89217ca54c3Smrg 0), \ 89317ca54c3Smrg (_Xos_processUnlock), \ 89417ca54c3Smrg (p).result ) 89517ca54c3Smrg 89617ca54c3Smrg#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(hpV4) 89717ca54c3Smrg/* Returns (int)0 on success. 89817ca54c3Smrg * 89917ca54c3Smrg * extern int asctime_r(const struct tm *timeptr, char *buffer, int buflen); 90017ca54c3Smrg * extern int ctime_r(const time_t *timer, char *buffer, int buflen); 90117ca54c3Smrg * extern int gmtime_r(const time_t *timer, struct tm *result); 90217ca54c3Smrg * extern int localtime_r(const time_t *timer, struct tm *result); 90317ca54c3Smrg */ 90417ca54c3Smrg# ifdef TIMELEN 90517ca54c3Smrgtypedef char _Xatimeparams[TIMELEN]; 90617ca54c3Smrgtypedef char _Xctimeparams[TIMELEN]; 90717ca54c3Smrg# else 90817ca54c3Smrgtypedef char _Xatimeparams[26]; 90917ca54c3Smrgtypedef char _Xctimeparams[26]; 91017ca54c3Smrg# endif 91117ca54c3Smrgtypedef struct tm _Xgtimeparams; 91217ca54c3Smrgtypedef struct tm _Xltimeparams; 91317ca54c3Smrg# define _XAsctime(t,p) (asctime_r((t),(p),sizeof((p))) ? NULL : (p)) 91417ca54c3Smrg# define _XCtime(t,p) (ctime_r((t),(p),sizeof((p))) ? NULL : (p)) 91517ca54c3Smrg# define _XGmtime(t,p) (gmtime_r((t),&(p)) ? NULL : &(p)) 91617ca54c3Smrg# define _XLocaltime(t,p) (localtime_r((t),&(p)) ? NULL : &(p)) 91717ca54c3Smrg 91817ca54c3Smrg#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(__sun) 91917ca54c3Smrg/* Returns NULL on failure. Solaris 2.5 92017ca54c3Smrg * 92117ca54c3Smrg * extern char *asctime_r(const struct tm *tm,char *buf, int buflen); 92217ca54c3Smrg * extern char *ctime_r(const time_t *clock, char *buf, int buflen); 92317ca54c3Smrg * extern struct tm *gmtime_r(const time_t *clock, struct tm *res); 92417ca54c3Smrg * extern struct tm *localtime_r(const time_t *clock, struct tm *res); 92517ca54c3Smrg */ 92617ca54c3Smrg# ifdef TIMELEN 92717ca54c3Smrgtypedef char _Xatimeparams[TIMELEN]; 92817ca54c3Smrgtypedef char _Xctimeparams[TIMELEN]; 92917ca54c3Smrg# else 93017ca54c3Smrgtypedef char _Xatimeparams[26]; 93117ca54c3Smrgtypedef char _Xctimeparams[26]; 93217ca54c3Smrg# endif 93317ca54c3Smrgtypedef struct tm _Xgtimeparams; 93417ca54c3Smrgtypedef struct tm _Xltimeparams; 93517ca54c3Smrg# define _XAsctime(t,p) asctime_r((t),(p),sizeof((p))) 93617ca54c3Smrg# define _XCtime(t,p) ctime_r((t),(p),sizeof((p))) 93717ca54c3Smrg# define _XGmtime(t,p) gmtime_r((t),&(p)) 93817ca54c3Smrg# define _XLocaltime(t,p) localtime_r((t),&(p)) 93917ca54c3Smrg 94017ca54c3Smrg#else /* defined(_POSIX_THREAD_SAFE_FUNCTIONS) */ 94117ca54c3Smrg/* POSIX final API. 94217ca54c3Smrg * extern char *asctime_r(const struct tm *timeptr, char *buffer); 94317ca54c3Smrg * extern char *ctime_r(const time_t *timer, char *buffer); 94417ca54c3Smrg * extern struct tm *gmtime_r(const time_t *timer, struct tm *result); 94517ca54c3Smrg * extern struct tm *localtime_r(const time_t *timer, struct tm *result); 94617ca54c3Smrg */ 94717ca54c3Smrg# ifdef TIMELEN 94817ca54c3Smrgtypedef char _Xatimeparams[TIMELEN]; 94917ca54c3Smrgtypedef char _Xctimeparams[TIMELEN]; 95017ca54c3Smrg# else 95117ca54c3Smrgtypedef char _Xatimeparams[26]; 95217ca54c3Smrgtypedef char _Xctimeparams[26]; 95317ca54c3Smrg# endif 95417ca54c3Smrgtypedef struct tm _Xgtimeparams; 95517ca54c3Smrgtypedef struct tm _Xltimeparams; 95617ca54c3Smrg# define _XAsctime(t,p) asctime_r((t),(p)) 95717ca54c3Smrg# define _XCtime(t,p) ctime_r((t),(p)) 95817ca54c3Smrg# define _XGmtime(t,p) gmtime_r((t),&(p)) 95917ca54c3Smrg# define _XLocaltime(t,p) localtime_r((t),&(p)) 96017ca54c3Smrg#endif /* X_INCLUDE_TIME_H */ 96117ca54c3Smrg 96217ca54c3Smrg#if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H) 96317ca54c3Smrg# define _XOS_INCLUDED_TIME_H 96417ca54c3Smrg#endif 96517ca54c3Smrg 96617ca54c3Smrg 96717ca54c3Smrg/***** <grp.h> wrappers *****/ 96817ca54c3Smrg 96917ca54c3Smrg/* 97017ca54c3Smrg * Effective prototypes for <grp.h> wrappers: 97117ca54c3Smrg * 97217ca54c3Smrg * NOTE: On systems lacking appropriate _r functions Getgrgid() and 97317ca54c3Smrg * Getgrnam() do NOT copy the list of group members! 97417ca54c3Smrg * 97517ca54c3Smrg * Remember that fgetgrent(), setgrent(), getgrent(), and endgrent() 97617ca54c3Smrg * are not included in POSIX. 97717ca54c3Smrg * 97817ca54c3Smrg * #define X_INCLUDE_GRP_H 97917ca54c3Smrg * #define XOS_USE_..._LOCKING 98017ca54c3Smrg * #include <X11/Xos_r.h> 98117ca54c3Smrg * 98217ca54c3Smrg * typedef ... _Xgetgrparams; 98317ca54c3Smrg * 98417ca54c3Smrg * struct group *_XGetgrgid(gid_t, _Xgetgrparams); 98517ca54c3Smrg * struct group *_XGetgrnam(const char *, _Xgetgrparams); 98617ca54c3Smrg */ 98717ca54c3Smrg 98817ca54c3Smrg#if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H) 98917ca54c3Smrg# include <grp.h> 99017ca54c3Smrg# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_GRPAPI) 99117ca54c3Smrg# define XOS_USE_MTSAFE_GRPAPI 1 99217ca54c3Smrg# endif 99317ca54c3Smrg#endif 99417ca54c3Smrg 99517ca54c3Smrg#if !defined(X_INCLUDE_GRP_H) || defined(_XOS_INCLUDED_GRP_H) 99617ca54c3Smrg/* Do nothing. */ 99717ca54c3Smrg 99817ca54c3Smrg#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 99917ca54c3Smrg/* Use regular, unsafe API. */ 100017ca54c3Smrgtypedef int _Xgetgrparams; /* dummy */ 100117ca54c3Smrg#define _XGetgrgid(g,p) getgrgid((g)) 100217ca54c3Smrg#define _XGetgrnam(n,p) getgrnam((n)) 100317ca54c3Smrg 100417ca54c3Smrg#elif !defined(XOS_USE_MTSAFE_GRPAPI) || defined(XNO_MTSAFE_GRPAPI) 100517ca54c3Smrg/* Systems with thread support but no _r API. UnixWare 2.0. */ 100617ca54c3Smrgtypedef struct { 100717ca54c3Smrg struct group grp; 100817ca54c3Smrg char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 100917ca54c3Smrg struct group *pgrp; 101017ca54c3Smrg size_t len; 101117ca54c3Smrg} _Xgetgrparams; 101217ca54c3Smrg#ifdef SVR4 101317ca54c3Smrg/* Copy the gr_passwd field too. */ 101417ca54c3Smrg# define _Xgrp_copyGroup(p) \ 101517ca54c3Smrg ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \ 101617ca54c3Smrg ((p).grp.gr_name = (p).buf), \ 101717ca54c3Smrg ((p).len = strlen((p).pgrp->gr_name)), \ 101817ca54c3Smrg strcpy((p).grp.gr_name, (p).pgrp->gr_name), \ 101917ca54c3Smrg ((p).grp.gr_passwd = (p).grp.gr_name + (p).len + 1), \ 102017ca54c3Smrg ((p).pgrp = &(p).grp), \ 102117ca54c3Smrg 0 ) 102217ca54c3Smrg#else 102317ca54c3Smrg# define _Xgrp_copyGroup(p) \ 102417ca54c3Smrg ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \ 102517ca54c3Smrg ((p).grp.gr_name = (p).buf), \ 102617ca54c3Smrg strcpy((p).grp.gr_name, (p).pgrp->gr_name), \ 102717ca54c3Smrg ((p).pgrp = &(p).grp), \ 102817ca54c3Smrg 0 ) 102917ca54c3Smrg#endif 103017ca54c3Smrg#define _XGetgrgid(g,p) \ 103117ca54c3Smrg ( (_Xos_processLock), \ 103217ca54c3Smrg (((p).pgrp = getgrgid((g))) ? _Xgrp_copyGroup(p) : 0), \ 103317ca54c3Smrg (_Xos_processUnlock), \ 103417ca54c3Smrg (p).pgrp ) 103517ca54c3Smrg#define _XGetgrnam(n,p) \ 103617ca54c3Smrg ( (_Xos_processLock), \ 103717ca54c3Smrg (((p).pgrp = getgrnam((n))) ? _Xgrp_copyGroup(p) : 0), \ 103817ca54c3Smrg (_Xos_processUnlock), \ 103917ca54c3Smrg (p).pgrp ) 104017ca54c3Smrg 104117ca54c3Smrg#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(__sun) 104217ca54c3Smrg/* Non-POSIX API. Solaris. 104317ca54c3Smrg * 104417ca54c3Smrg * extern struct group *getgrgid_r(gid_t, struct group *, char *, int); 104517ca54c3Smrg * extern struct group *getgrnam_r(const char *, struct group *, char *, int); 104617ca54c3Smrg */ 104717ca54c3Smrgtypedef struct { 104817ca54c3Smrg struct group grp; 104917ca54c3Smrg char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 105017ca54c3Smrg} _Xgetgrparams; 105117ca54c3Smrg#define _XGetgrgid(g,p) getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) 105217ca54c3Smrg#define _XGetgrnam(n,p) getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) 105317ca54c3Smrg 105417ca54c3Smrg#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) 105517ca54c3Smrg/* Non-POSIX API. 105617ca54c3Smrg * extern int getgrgid_r(gid_t, struct group *, char *, int); 105717ca54c3Smrg * extern int getgrnam_r(const char *, struct group *, char *, int); 105817ca54c3Smrg */ 105917ca54c3Smrgtypedef struct { 106017ca54c3Smrg struct group grp; 106117ca54c3Smrg char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 106217ca54c3Smrg} _Xgetgrparams; 106317ca54c3Smrg#define _XGetgrgid(g,p) \ 106417ca54c3Smrg ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp)) 106517ca54c3Smrg#define _XGetgrnam(n,p) \ 106617ca54c3Smrg ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp)) 106717ca54c3Smrg 106817ca54c3Smrg#else 106917ca54c3Smrg/* POSIX final API. 107017ca54c3Smrg * 107117ca54c3Smrg * int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); 107217ca54c3Smrg * int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); 107317ca54c3Smrg */ 107417ca54c3Smrgtypedef struct { 107517ca54c3Smrg struct group grp; 107617ca54c3Smrg char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 107717ca54c3Smrg struct group *result; 107817ca54c3Smrg} _Xgetgrparams; 107917ca54c3Smrg 108017ca54c3Smrg#define _XGetgrgid(g,p) \ 108117ca54c3Smrg ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \ 108217ca54c3Smrg NULL : (p).result)) 108317ca54c3Smrg#define _XGetgrnam(n,p) \ 108417ca54c3Smrg ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \ 108517ca54c3Smrg NULL : (p).result)) 108617ca54c3Smrg#endif 108717ca54c3Smrg 108817ca54c3Smrg#if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H) 108917ca54c3Smrg# define _XOS_INCLUDED_GRP_H 109017ca54c3Smrg#endif 109117ca54c3Smrg 109217ca54c3Smrg 109317ca54c3Smrg#ifdef __cplusplus 109417ca54c3Smrg} /* Close scope of 'extern "C"' declaration which encloses file. */ 109517ca54c3Smrg#endif 1096