Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:31

0001 /* $Xorg: Xos_r.h,v 1.3 2000/08/18 04:05:44 coskrey Exp $ */
0002 /* 
0003 Copyright 1996, 1998  The Open Group
0004 
0005 All Rights Reserved.
0006 
0007 The above copyright notice and this permission notice shall be included in
0008 all copies or substantial portions of the Software.
0009 
0010 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0011 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0012 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0013 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0014 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0015 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0016 
0017 Except as contained in this notice, the name of The Open Group shall not be
0018 used in advertising or otherwise to promote the sale, use or other dealings
0019 in this Software without prior written authorization from The Open Group.
0020 */
0021 /* $XFree86: xc/include/Xos_r.h,v 1.9 2001/03/02 23:01:28 dawes Exp $ */
0022 
0023 /* 
0024  * Various and sundry Thread-Safe functions used by X11, Motif, and CDE.
0025  *
0026  * Use this file in MT-safe code where you would have included
0027  *  <dirent.h>  for readdir()
0028  *  <grp.h>     for getgrgid() or getgrnam()
0029  *  <netdb.h>   for gethostbyname(), gethostbyaddr(), or getservbyname()
0030  *  <pwd.h>     for getpwnam() or getpwuid()
0031  *  <string.h>  for strtok()
0032  *  <time.h>    for asctime(), ctime(), localtime(), or gmtime()
0033  *  <unistd.h>  for getlogin() or ttyname()
0034  * or their thread-safe analogs.
0035  *
0036  * If you are on a platform that defines XTHREADS but does not have
0037  * MT-safe system API (e.g. UnixWare) you must define _Xos_processLock
0038  * and _Xos_processUnlock macros before including this header.  If
0039  * you are on OSF/1 V3.2 and plan to use readdir(), you must also define
0040  * _Xos_isThreadsInitialized.  For convenience XOS_USE_XLIB_LOCKING or
0041  * XOS_USE_XT_LOCKING may be defined to obtain either Xlib-only or
0042  * Xt-based versions of these macros.  These macros won't result in
0043  * truly thread-safe calls, but they are better than nothing.  If you
0044  * do not want locking in this situation define XOS_USE_NO_LOCKING.
0045  *
0046  * NOTE: On systems lacking approriate _r functions Gethostbyname(),
0047  *  Gethostbyaddr(), and Getservbyname() do NOT copy the host or
0048  *  protocol lists!
0049  *
0050  * NOTE: On systems lacking appropriate _r functions Getgrgid() and
0051  *  Getgrnam() do NOT copy the list of group members!
0052  *
0053  * This header is nominally intended to simplify porting X11, Motif, and 
0054  * CDE; it may be useful to other people too.  The structure below is
0055  * complicated, mostly because P1003.1c (the IEEE POSIX Threads spec)
0056  * went through lots of drafts, and some vendors shipped systems based
0057  * on draft API that were changed later.  Unfortunately POSIX did not
0058  * provide a feature-test macro for distinguishing each of the drafts.
0059  */
0060 
0061 /*
0062  * This header has several parts.  Search for "Effective prototypes"
0063  * to locate the beginning of a section.
0064  */
0065 
0066 /* This header can be included multiple times with different defines! */
0067 #ifndef _XOS_R_H_
0068 # define _XOS_R_H_
0069 
0070 # include <X11/Xos.h>
0071 # include <X11/Xfuncs.h>
0072 
0073 # ifndef X_NOT_POSIX
0074 #  ifdef _POSIX_SOURCE
0075 #   include <limits.h>
0076 #  else
0077 #   define _POSIX_SOURCE
0078 #   include <limits.h>
0079 #   undef _POSIX_SOURCE
0080 #  endif
0081 #  ifndef LINE_MAX
0082 #   define X_LINE_MAX 2048
0083 #  else
0084 #   define X_LINE_MAX LINE_MAX
0085 #  endif
0086 # endif
0087 #endif /* _XOS_R_H */
0088 
0089 #ifndef WIN32
0090 
0091 #ifdef __cplusplus
0092 extern "C" {
0093 #endif
0094 
0095 # if defined(XOS_USE_XLIB_LOCKING)
0096 #  ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
0097 typedef struct _LockInfoRec *LockInfoPtr;
0098 extern LockInfoPtr _Xglobal_lock;
0099 #  endif
0100 #  ifndef _Xos_isThreadInitialized
0101 #   define _Xos_isThreadInitialized (_Xglobal_lock)
0102 #  endif
0103 #  if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
0104 #   ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
0105 #    include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */
0106 extern void (*_XLockMutex_fn)(
0107 #    if NeedFunctionPrototypes
0108     LockInfoPtr /* lock */, char * /* file */, int /* line */
0109 #    endif
0110 );
0111 extern void (*_XUnlockMutex_fn)(
0112 #    if NeedFunctionPrototypes
0113     LockInfoPtr /* lock */, char * /* file */, int /* line */
0114 #    endif
0115 );
0116 #   endif
0117 #   ifndef _Xos_processLock
0118 #    define _Xos_processLock    \
0119   (_XLockMutex_fn ? (*_XLockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)
0120 #   endif
0121 #   ifndef _Xos_processUnlock
0122 #    define _Xos_processUnlock  \
0123   (_XUnlockMutex_fn ? (*_XUnlockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)
0124 #   endif
0125 #  else
0126 #   ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
0127 #    include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */
0128 extern void (*_XLockMutex_fn)(
0129 #    if NeedFunctionPrototypes
0130     LockInfoPtr /* lock */
0131 #    endif
0132 );
0133 extern void (*_XUnlockMutex_fn)(
0134 #    if NeedFunctionPrototypes
0135     LockInfoPtr /* lock */
0136 #    endif
0137 );
0138 #   endif
0139 #   ifndef _Xos_processLock
0140 #    define _Xos_processLock    \
0141   (_XLockMutex_fn ? ((*_XLockMutex_fn)(_Xglobal_lock), 0) : 0)
0142 #   endif
0143 #   ifndef _Xos_processUnlock
0144 #    define _Xos_processUnlock  \
0145   (_XUnlockMutex_fn ? ((*_XUnlockMutex_fn)(_Xglobal_lock), 0) : 0)
0146 #   endif
0147 #  endif
0148 # elif defined(XOS_USE_XT_LOCKING)
0149 extern void (*_XtProcessLock)(void);
0150 #  ifndef _XtintrinsicP_h
0151 #   include <X11/Xfuncproto.h>  /* for NeedFunctionPrototypes */
0152 extern void XtProcessLock(
0153 #   if NeedFunctionPrototypes
0154     void
0155 #   endif
0156 );
0157 extern void XtProcessUnlock(
0158 #   if NeedFunctionPrototypes
0159     void
0160 #   endif
0161 );
0162 #  endif
0163 #  ifndef _Xos_isThreadInitialized
0164 #   define _Xos_isThreadInitialized _XtProcessLock
0165 #  endif
0166 #  ifndef _Xos_processLock
0167 #   define _Xos_processLock     XtProcessLock()
0168 #  endif
0169 #  ifndef _Xos_processUnlock
0170 #   define _Xos_processUnlock       XtProcessUnlock()
0171 #  endif
0172 # elif defined(XOS_USE_NO_LOCKING)
0173 #  ifndef _Xos_isThreadInitialized
0174 #   define _Xos_isThreadInitialized 0
0175 #  endif
0176 #  ifndef _Xos_processLock
0177 #   define _Xos_processLock     0
0178 #  endif
0179 #  ifndef _Xos_processUnlock
0180 #   define _Xos_processUnlock       0
0181 #  endif
0182 # endif
0183 
0184 #endif /* !defined WIN32 */
0185 
0186 /* 
0187  * Solaris 2.5 has SVR4 thread-safe API, but defines the POSIX
0188  * thread-safe feature test macro.  Fix the feature test macro.
0189  */
0190 #if defined(sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0191 # undef _POSIX_THREAD_SAFE_FUNCTIONS
0192 #endif
0193 
0194 /*
0195  * LynxOS 3.1 defines _POSIX_THREAD_SAFE_FUNCTIONS but 
0196  * getpwuid_r has different semantics than defined by POSIX
0197  */
0198 #if defined(Lynx) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0199 # undef _POSIX_THREAD_SAFE_FUNCTIONS
0200 #endif
0201 
0202 
0203 /***** <pwd.h> wrappers *****/
0204 
0205 /*
0206  * Effective prototypes for <pwd.h> wrappers:
0207  *
0208  * #define X_INCLUDE_PWD_H
0209  * #define XOS_USE_..._LOCKING
0210  * #include <X11/Xos_r.h>
0211  *
0212  * typedef ... _Xgetpwparams;
0213  *
0214  * struct passwd* _XGetpwnam(const char *name, _Xgetpwparams);
0215  * struct passwd* _XGetpwuid(uid_t uid, _Xgetpwparams);
0216  */
0217 
0218 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
0219 # include <pwd.h>
0220 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI)
0221 #  define XOS_USE_MTSAFE_PWDAPI 1
0222 # endif
0223 #endif
0224 
0225 #if !defined(X_INCLUDE_PWD_H) || defined(_XOS_INCLUDED_PWD_H)
0226 /* Do nothing */
0227 
0228 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0229 /* Use regular, unsafe API. */
0230 # if defined(X_NOT_POSIX) && !defined(i386) && !defined(SYSV)
0231 extern struct passwd *getpwuid(), *getpwnam();
0232 # endif
0233 typedef int _Xgetpwparams;  /* dummy */
0234 # define _XGetpwuid(u,p)    getpwuid((u))
0235 # define _XGetpwnam(u,p)    getpwnam((u))
0236 
0237 #elif !defined(XOS_USE_MTSAFE_PWDAPI) || defined(XNO_MTSAFE_PWDAPI)
0238 /* UnixWare 2.0, or other systems with thread support but no _r API. */
0239 typedef struct {
0240   struct passwd pws;
0241   char   pwbuf[1024];
0242   struct passwd* pwp;
0243   size_t len;
0244 } _Xgetpwparams;
0245 
0246 /*
0247  * NetBSD and FreeBSD, at least, are missing several of the unixware passwd
0248  * fields.
0249  */
0250    
0251 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
0252 __inline__ void _Xpw_copyPasswd(_Xgetpwparams p)
0253 {
0254    memcpy(&(p).pws, (p).pwp, sizeof(struct passwd));
0255 
0256    (p).pws.pw_name = (p).pwbuf;
0257    (p).len = strlen((p).pwp->pw_name);
0258    strcpy((p).pws.pw_name, (p).pwp->pw_name);
0259 
0260    (p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1;
0261    (p).len = strlen((p).pwp->pw_passwd);
0262    strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd);
0263 
0264    (p).pws.pw_class = (p).pws.pw_passwd + (p).len + 1;
0265    (p).len = strlen((p).pwp->pw_class);
0266    strcpy((p).pws.pw_class, (p).pwp->pw_class);
0267 
0268    (p).pws.pw_gecos = (p).pws.pw_class + (p).len + 1;
0269    (p).len = strlen((p).pwp->pw_gecos);
0270    strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos);
0271 
0272    (p).pws.pw_dir = (p).pws.pw_gecos + (p).len + 1;
0273    (p).len = strlen((p).pwp->pw_dir);
0274    strcpy((p).pws.pw_dir, (p).pwp->pw_dir);
0275 
0276    (p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1;
0277    (p).len = strlen((p).pwp->pw_shell);
0278    strcpy((p).pws.pw_shell, (p).pwp->pw_shell);
0279 
0280    (p).pwp = &(p).pws;
0281 }
0282 
0283 #else
0284 # define _Xpw_copyPasswd(p) \
0285    (memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)), \
0286     ((p).pws.pw_name = (p).pwbuf), \
0287     ((p).len = strlen((p).pwp->pw_name)), \
0288     strcpy((p).pws.pw_name, (p).pwp->pw_name), \
0289     ((p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1), \
0290     ((p).len = strlen((p).pwp->pw_passwd)), \
0291     strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd), \
0292     ((p).pws.pw_age = (p).pws.pw_passwd + (p).len + 1), \
0293     ((p).len = strlen((p).pwp->pw_age)), \
0294     strcpy((p).pws.pw_age, (p).pwp->pw_age), \
0295     ((p).pws.pw_comment = (p).pws.pw_age + (p).len + 1), \
0296     ((p).len = strlen((p).pwp->pw_comment)), \
0297     strcpy((p).pws.pw_comment, (p).pwp->pw_comment), \
0298     ((p).pws.pw_gecos = (p).pws.pw_comment + (p).len + 1), \
0299     ((p).len = strlen((p).pwp->pw_gecos)), \
0300     strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos), \
0301     ((p).pws.pw_dir = (p).pws.pw_comment + (p).len + 1), \
0302     ((p).len = strlen((p).pwp->pw_dir)), \
0303     strcpy((p).pws.pw_dir, (p).pwp->pw_dir), \
0304     ((p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1), \
0305     ((p).len = strlen((p).pwp->pw_shell)), \
0306     strcpy((p).pws.pw_shell, (p).pwp->pw_shell), \
0307     ((p).pwp = &(p).pws), \
0308     0 )
0309 #endif
0310 # define _XGetpwuid(u,p) \
0311 ( (_Xos_processLock), \
0312   (((p).pwp = getpwuid((u))) ? _Xpw_copyPasswd(p) : 0), \
0313   (_Xos_processUnlock), \
0314   (p).pwp )
0315 # define _XGetpwnam(u,p) \
0316 ( (_Xos_processLock), \
0317   (((p).pwp = getpwnam((u))) ? _Xpw_copyPasswd(p) : 0), \
0318   (_Xos_processUnlock), \
0319   (p).pwp )
0320 
0321 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0322 /* SVR4 threads, AIX 4.2.0 and earlier and OSF/1 3.2 and earlier pthreads */
0323 typedef struct {
0324   struct passwd pws;
0325   char pwbuf[X_LINE_MAX];
0326 } _Xgetpwparams;
0327 # if defined(_POSIX_REENTRANT_FUNCTIONS) || !defined(SVR4) || defined(Lynx)
0328 #  ifndef Lynx
0329 #   define _XGetpwuid(u,p) \
0330 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
0331 #   define _XGetpwnam(u,p) \
0332 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
0333 #  else /* Lynx */
0334 #   define _XGetpwuid(u,p) \
0335 ((getpwuid_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
0336 #   define _XGetpwnam(u,p) \
0337 ((getpwnam_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
0338 #  endif
0339 # else /* SVR4 */
0340 #  define _XGetpwuid(u,p) \
0341 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)
0342 #  define _XGetpwnam(u,p) \
0343 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)
0344 # endif /* SVR4 */
0345 
0346 #else /* _POSIX_THREAD_SAFE_FUNCTIONS */
0347 /* Digital UNIX 4.0, but not (beta) T4.0-1 */
0348 # if defined(__osf__)
0349 /* OSF/1 V4.0 <pwd.h> doesn't declare the _P routines, breaking under C++. */
0350 extern int _Pgetpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
0351 extern int _Pgetpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
0352 # endif
0353 typedef struct {
0354   struct passwd pws;
0355   char pwbuf[X_LINE_MAX];
0356   struct passwd* pwp;
0357 } _Xgetpwparams;
0358 typedef int _Xgetpwret;
0359 # define _XGetpwuid(u,p) \
0360 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \
0361  NULL : (p).pwp)
0362 # define _XGetpwnam(u,p) \
0363 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \
0364  NULL : (p).pwp)
0365 #endif /* X_INCLUDE_PWD_H */
0366 
0367 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
0368 # define _XOS_INCLUDED_PWD_H
0369 #endif
0370 
0371 
0372 /***** <netdb.h> wrappers *****/
0373 
0374 /* 
0375  * Effective prototypes for <netdb.h> wrappers:
0376  *
0377  * NOTE: On systems lacking the appropriate _r functions Gethostbyname(),
0378  *  Gethostbyaddr(), and Getservbyname() do NOT copy the host or
0379  *  protocol lists!
0380  *
0381  * #define X_INCLUDE_NETDB_H
0382  * #define XOS_USE_..._LOCKING
0383  * #include <X11/Xos_r.h>
0384  *
0385  * typedef ... _Xgethostbynameparams;
0386  * typedef ... _Xgetservbynameparams;
0387  *
0388  * struct hostent* _XGethostbyname(const char* name,_Xgethostbynameparams);
0389  * struct hostent* _XGethostbyaddr(const char* addr, int len, int type, 
0390  *                 _Xgethostbynameparams);
0391  * struct servent* _XGetservbyname(const char* name, const char* proto,
0392  *               _Xgetservbynameparams);
0393  */
0394 
0395 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \
0396     && !defined(WIN32)
0397 # include <netdb.h>
0398 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI)
0399 #  define XOS_USE_MTSAFE_NETDBAPI 1
0400 # endif
0401 #endif
0402 
0403 #if !defined(X_INCLUDE_NETDB_H) || defined(_XOS_INCLUDED_NETDB_H)
0404 /* Do nothing. */
0405 
0406 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0407 /* Use regular, unsafe API. */
0408 typedef int _Xgethostbynameparams; /* dummy */
0409 typedef int _Xgetservbynameparams; /* dummy */
0410 # define _XGethostbyname(h,hp)      gethostbyname((h))
0411 # define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t))
0412 # define _XGetservbyname(s,p,sp)    getservbyname((s),(p))
0413 
0414 #elif !defined(XOS_USE_MTSAFE_NETDBAPI) || defined(XNO_MTSAFE_NETDBAPI)
0415 /* UnixWare 2.0, or other systems with thread support but no _r API. */
0416 /* WARNING:  The h_addr_list and s_aliases values are *not* copied! */
0417 
0418 #if defined(__NetBSD__) || defined(__FreeBSD__)
0419 #include <sys/param.h>
0420 #endif
0421 
0422 typedef struct {
0423   struct hostent hent;
0424   char           h_name[MAXHOSTNAMELEN];
0425   struct hostent *hptr;
0426 } _Xgethostbynameparams;
0427 typedef struct {
0428   struct servent sent;
0429   char           s_name[255];
0430   char       s_proto[255];
0431   struct servent *sptr;
0432 } _Xgetservbynameparams;
0433 # define _Xg_copyHostent(hp) \
0434    (memcpy(&(hp).hent, (hp).hptr, sizeof(struct hostent)), \
0435     strcpy((hp).h_name, (hp).hptr->h_name), \
0436     ((hp).hent.h_name = (hp).h_name), \
0437     ((hp).hptr = &(hp).hent), \
0438      0 )
0439 # define _Xg_copyServent(sp) \
0440    (memcpy(&(sp).sent, (sp).sptr, sizeof(struct servent)), \
0441     strcpy((sp).s_name, (sp).sptr->s_name), \
0442     ((sp).sent.s_name = (sp).s_name), \
0443     strcpy((sp).s_proto, (sp).sptr->s_proto), \
0444     ((sp).sent.s_proto = (sp).s_proto), \
0445     ((sp).sptr = &(sp).sent), \
0446     0 )
0447 # define _XGethostbyname(h,hp) \
0448    ((_Xos_processLock), \
0449     (((hp).hptr = gethostbyname((h))) ? _Xg_copyHostent(hp) : 0), \
0450     (_Xos_processUnlock), \
0451     (hp).hptr )
0452 # define _XGethostbyaddr(a,al,t,hp) \
0453    ((_Xos_processLock), \
0454     (((hp).hptr = gethostbyaddr((a),(al),(t))) ? _Xg_copyHostent(hp) : 0), \
0455     (_Xos_processUnlock), \
0456     (hp).hptr )
0457 # define _XGetservbyname(s,p,sp) \
0458    ((_Xos_processLock), \
0459     (((sp).sptr = getservbyname((s),(p))) ? _Xg_copyServent(sp) : 0), \
0460     (_Xos_processUnlock), \
0461     (sp).sptr )
0462 
0463 #elif defined(XUSE_NETDB_R_API)
0464 /*
0465  * POSIX does not specify _r equivalents for <netdb.h> API, but some
0466  * vendors provide them anyway.  Use them only when explicitly asked.
0467  */
0468 # ifdef _POSIX_REENTRANT_FUNCTIONS
0469 #  ifndef _POSIX_THREAD_SAFE_FUNCTIONS
0470 #   if defined(AIXV3) || defined(AIXV4) || defined(__osf__)
0471 #    define X_POSIX_THREAD_SAFE_FUNCTIONS 1
0472 #   endif
0473 #  endif
0474 # endif
0475 # ifdef _POSIX_THREAD_SAFE_FUNCTIONS
0476 #  define X_POSIX_THREAD_SAFE_FUNCTIONS 1
0477 # endif
0478 
0479 # ifndef X_POSIX_THREAD_SAFE_FUNCTIONS
0480 typedef struct {
0481     struct hostent      hent;
0482     char                hbuf[X_LINE_MAX];
0483     int                 herr;
0484 } _Xgethostbynameparams;
0485 typedef struct {
0486     struct servent      sent;
0487     char                sbuf[X_LINE_MAX];
0488 } _Xgetservbynameparams;
0489 #  define _XGethostbyname(h,hp) \
0490   gethostbyname_r((h),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr)
0491 #  define _XGethostbyaddr(a,al,t,hp) \
0492   gethostbyaddr_r((a),(al),(t),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr)
0493 #  define _XGetservbyname(s,p,sp) \
0494   getservbyname_r((s),(p),&(sp).sent,(sp).sbuf,sizeof((sp).sbuf))
0495 # else
0496 typedef struct {
0497   struct hostent      hent;
0498   struct hostent_data hdata;
0499 } _Xgethostbynameparams;
0500 typedef struct {
0501   struct servent      sent;
0502   struct servent_data sdata;
0503 } _Xgetservbynameparams;
0504 #  define _XGethostbyname(h,hp) \
0505   (bzero((char*)&(hp).hdata,sizeof((hp).hdata)),    \
0506    ((gethostbyname_r((h),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent))
0507 #  define _XGethostbyaddr(a,al,t,hp) \
0508   (bzero((char*)&(hp).hdata,sizeof((hp).hdata)),    \
0509    ((gethostbyaddr_r((a),(al),(t),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent))
0510 #  define _XGetservbyname(s,p,sp) \
0511   (bzero((char*)&(sp).sdata,sizeof((sp).sdata)),    \
0512    ((getservbyname_r((s),(p),&(sp).sent,&(sp).sdata) == -1) ? NULL : &(sp).sent) )
0513 # endif
0514 # ifdef X_POSIX_THREAD_SAFE_FUNCTIONS
0515 #  undef X_POSIX_THREAD_SAFE_FUNCTIONS
0516 # endif
0517 
0518 #else
0519 /* The regular API is assumed to be MT-safe under POSIX. */
0520 typedef int _Xgethostbynameparams; /* dummy */
0521 typedef int _Xgetservbynameparams; /* dummy */
0522 # define _XGethostbyname(h,hp)      gethostbyname((h))
0523 # define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t))
0524 # define _XGetservbyname(s,p,sp)    getservbyname((s),(p))
0525 #endif /* X_INCLUDE_NETDB_H */
0526 
0527 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H)
0528 # define _XOS_INCLUDED_NETDB_H
0529 #endif
0530 
0531 
0532 /***** <dirent.h> wrappers *****/
0533 
0534 /*
0535  * Effective prototypes for <dirent.h> wrappers:
0536  *
0537  * #define X_INCLUDE_DIRENT_H
0538  * #define XOS_USE_..._LOCKING
0539  * #include <X11/Xos_r.h>
0540  * 
0541  * typedef ... _Xreaddirparams;
0542  *
0543  * struct dirent *_XReaddir(DIR *dir_pointer, _Xreaddirparams);
0544  */
0545 
0546 #if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H)
0547 # include <sys/types.h>
0548 # if !defined(X_NOT_POSIX) || defined(SYSV) || defined(USG)
0549 #  include <dirent.h>
0550 # else
0551 #  include <sys/dir.h>
0552 #  ifndef dirent
0553 #   define dirent direct
0554 #  endif
0555 # endif
0556 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_DIRENTAPI)
0557 #  define XOS_USE_MTSAFE_DIRENTAPI 1
0558 # endif
0559 #endif
0560 
0561 #if !defined(X_INCLUDE_DIRENT_H) || defined(_XOS_INCLUDED_DIRENT_H)
0562 /* Do nothing. */
0563 
0564 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0565 /* Use regular, unsafe API. */
0566 typedef int _Xreaddirparams;    /* dummy */
0567 # define _XReaddir(d,p) readdir(d)
0568 
0569 #elif !defined(XOS_USE_MTSAFE_DIRENTAPI) || defined(XNO_MTSAFE_DIRENTAPI)
0570 /* Systems with thread support but no _r API. */
0571 typedef struct {
0572   struct dirent *result;
0573   struct dirent dir_entry;
0574 # ifdef _POSIX_PATH_MAX
0575   char buf[_POSIX_PATH_MAX];
0576 # elif defined(NAME_MAX)
0577   char buf[NAME_MAX];
0578 # else
0579   char buf[255];
0580 # endif
0581 } _Xreaddirparams;
0582 
0583 # define _XReaddir(d,p) \
0584  ( (_Xos_processLock),                       \
0585    (((p).result = readdir((d))) ?                \
0586     (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \
0587      ((p).result = &(p).dir_entry), 0) :             \
0588     0),                              \
0589    (_Xos_processUnlock),                     \
0590    (p).result )
0591 
0592 #else
0593 typedef struct {
0594   struct dirent *result;
0595   struct dirent dir_entry;
0596 # ifdef _POSIX_PATH_MAX
0597   char buf[_POSIX_PATH_MAX];
0598 # elif defined(NAME_MAX)
0599   char buf[NAME_MAX];
0600 # else
0601   char buf[255];
0602 # endif
0603 } _Xreaddirparams;
0604 
0605 # if defined(AIXV3) || defined(AIXV4) || defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0606 /* AIX defines the draft POSIX symbol, but uses the final API. */
0607 /* POSIX final API, returns (int)0 on success. */
0608 #  if defined(__osf__)
0609 /* OSF/1 V4.0 <dirent.h> doesn't declare _Preaddir_r, breaking under C++. */
0610 extern int _Preaddir_r(DIR *, struct dirent *, struct dirent **);
0611 #  endif
0612 #  define _XReaddir(d,p)                        \
0613     (readdir_r((d), &((p).dir_entry), &((p).result)) ? NULL : (p).result)
0614 # elif defined(_POSIX_REENTRANT_FUNCTIONS) && defined(__osf__)
0615 /*
0616  * OSF/1 V3.2 readdir_r() will SEGV if the main program is not
0617  * explicitly linked with -lc_r.  The library REQUIREDLIBS don't help.
0618  * Assume that if threads have been initialized we're linked properly.
0619  */
0620 #  define _XReaddir(d,p)                        \
0621  ( (_Xos_isThreadInitialized) ?                     \
0622    (readdir_r((d), &((p).dir_entry)) ? NULL : &((p).dir_entry)) :   \
0623    ((_Xos_processLock),                         \
0624     (((p).result = readdir((d))) ?                  \
0625      (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen),   \
0626       ((p).result = &(p).dir_entry), 0) :               \
0627      0),                                \
0628     (_Xos_processUnlock),                       \
0629     (p).result) )
0630 # elif defined(_POSIX_REENTRANT_FUNCTIONS)
0631 /* POSIX draft API, returns (int)0 on success. */
0632 #  define _XReaddir(d,p)    \
0633     (readdir_r((d),&((p).dir_entry)) ? NULL : &((p).dir_entry))
0634 # elif defined(SVR4)
0635 /* Pre-POSIX API, returns non-NULL on success. */
0636 #  define _XReaddir(d,p)    (readdir_r((d), &(p).dir_entry))
0637 # else
0638 /* We have no idea what is going on.  Fake it all using process locks. */
0639 #  define _XReaddir(d,p)    \
0640     ( (_Xos_processLock),                       \
0641       (((p).result = readdir((d))) ?                    \
0642        (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \
0643     ((p).result = &(p).dir_entry), 0) :             \
0644        0),                              \
0645       (_Xos_processUnlock),                     \
0646       (p).result )
0647 # endif
0648 #endif /* X_INCLUDE_DIRENT_H */
0649 
0650 #if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H)
0651 # define _XOS_INCLUDED_DIRENT_H
0652 #endif
0653 
0654 
0655 /***** <unistd.h> wrappers *****/
0656 
0657 /*
0658  * Effective prototypes for <unistd.h> wrappers:
0659  *
0660  * #define X_INCLUDE_UNISTD_H
0661  * #define XOS_USE_..._LOCKING
0662  * #include <X11/Xos_r.h>
0663  * 
0664  * typedef ... _Xgetloginparams;
0665  * typedef ... _Xttynameparams;
0666  *
0667  * char *_XGetlogin(_Xgetloginparams);
0668  * char *_XTtyname(int, _Xttynameparams);
0669  */
0670 
0671 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
0672 /* <unistd.h> already included by <X11/Xos.h> */
0673 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_UNISTDAPI)
0674 #  define XOS_USE_MTSAFE_UNISTDAPI 1
0675 # endif
0676 #endif
0677 
0678 #if !defined(X_INCLUDE_UNISTD_H) || defined(_XOS_INCLUDED_UNISTD_H)
0679 /* Do nothing. */
0680 
0681 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0682 /* Use regular, unsafe API. */
0683 typedef int _Xgetloginparams;   /* dummy */
0684 typedef int _Xttynameparams;    /* dummy */
0685 # define _XGetlogin(p)  getlogin()
0686 # define _XTtyname(f)   ttyname((f))
0687 
0688 #elif !defined(XOS_USE_MTSAFE_UNISTDAPI) || defined(XNO_MTSAFE_UNISTDAPI)
0689 /* Systems with thread support but no _r API. */
0690 typedef struct {
0691   char *result;
0692 # if defined(MAXLOGNAME)
0693   char buf[MAXLOGNAME];
0694 # elif defined(LOGIN_NAME_MAX)
0695   char buf[LOGIN_NAME_MAX];
0696 # else
0697   char buf[64];
0698 # endif
0699 } _Xgetloginparams;
0700 typedef struct {
0701   char *result;
0702 # ifdef TTY_NAME_MAX
0703   char buf[TTY_NAME_MAX];
0704 # elif defined(_POSIX_TTY_NAME_MAX)
0705   char buf[_POSIX_TTY_NAME_MAX];
0706 # elif defined(_POSIX_PATH_MAX)
0707   char buf[_POSIX_PATH_MAX];
0708 # else
0709   char buf[256];
0710 # endif
0711 } _Xttynameparams;
0712 
0713 # define _XGetlogin(p) \
0714  ( (_Xos_processLock), \
0715    (((p).result = getlogin()) ? \
0716     (strncpy((p).buf, (p).result, sizeof((p).buf)), \
0717      ((p).buf[sizeof((p).buf)-1] = '\0'), \
0718      ((p).result = (p).buf), 0) : 0), \
0719    (_Xos_processUnlock), \
0720    (p).result )
0721 #define _XTtyname(f,p) \
0722  ( (_Xos_processLock), \
0723    (((p).result = ttyname(f)) ? \
0724     (strncpy((p).buf, (p).result, sizeof((p).buf)), \
0725      ((p).buf[sizeof((p).buf)-1] = '\0'), \
0726      ((p).result = (p).buf), 0) : 0), \
0727    (_Xos_processUnlock), \
0728    (p).result )
0729 
0730 #elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_POSIX_REENTRANT_FUNCTIONS)
0731 /* POSIX API.
0732  *
0733  * extern int getlogin_r(char *, size_t);
0734  * extern int ttyname_r(int, char *, size_t);
0735  */
0736 typedef struct {
0737 # if defined(MAXLOGNAME)
0738   char buf[MAXLOGNAME];
0739 # elif defined(LOGIN_NAME_MAX)
0740   char buf[LOGIN_NAME_MAX];
0741 # else
0742   char buf[64];
0743 # endif
0744 } _Xgetloginparams;
0745 typedef struct {
0746 # ifdef TTY_NAME_MAX
0747   char buf[TTY_NAME_MAX];
0748 # elif defined(_POSIX_TTY_NAME_MAX)
0749   char buf[_POSIX_TTY_NAME_MAX];
0750 # elif defined(_POSIX_PATH_MAX)
0751   char buf[_POSIX_PATH_MAX];
0752 # else
0753   char buf[256];
0754 # endif
0755 } _Xttynameparams;
0756 
0757 # define _XGetlogin(p)  (getlogin_r((p).buf, sizeof((p).buf)) ? NULL : (p).buf)
0758 # define _XTtyname(f,p) \
0759     (ttyname_r((f), (p).buf, sizeof((p).buf)) ? NULL : (p).buf)
0760 
0761 #else
0762 /* Pre-POSIX API.
0763  *
0764  * extern char *getlogin_r(char *, size_t);
0765  * extern char *ttyname_r(int, char *, size_t);
0766  */
0767 typedef struct {
0768 # if defined(MAXLOGNAME)
0769   char buf[MAXLOGNAME];
0770 # elif defined(LOGIN_NAME_MAX)
0771   char buf[LOGIN_NAME_MAX];
0772 # else
0773   char buf[64];
0774 # endif
0775 } _Xgetloginparams;
0776 typedef struct {
0777 # ifdef TTY_NAME_MAX
0778   char buf[TTY_NAME_MAX];
0779 # elif defined(_POSIX_TTY_NAME_MAX)
0780   char buf[_POSIX_TTY_NAME_MAX];
0781 # elif defined(_POSIX_PATH_MAX)
0782   char buf[_POSIX_PATH_MAX];
0783 # else
0784   char buf[256];
0785 # endif
0786 } _Xttynameparams;
0787 
0788 # define _XGetlogin(p)  getlogin_r((p).buf, sizeof((p).buf))
0789 # define _XTtyname(f,p) ttyname_r((f), (p).buf, sizeof((p).buf))
0790 #endif /* X_INCLUDE_UNISTD_H */
0791 
0792 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
0793 # define _XOS_INCLUDED_UNISTD_H
0794 #endif
0795 
0796 
0797 /***** <string.h> wrappers *****/
0798 
0799 /*
0800  * Effective prototypes for <string.h> wrappers:
0801  *
0802  * #define X_INCLUDE_STRING_H
0803  * #define XOS_USE_..._LOCKING
0804  * #include <X11/Xos_r.h>
0805  *
0806  * typedef ... _Xstrtokparams;
0807  *
0808  * char *_XStrtok(char *, const char*, _Xstrtokparams);
0809  */
0810 
0811 #if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H)
0812 /* <string.h> has already been included by <X11/Xos.h> */
0813 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_STRINGAPI)
0814 #  define XOS_USE_MTSAFE_STRINGAPI 1
0815 # endif
0816 #endif
0817 
0818 #if !defined(X_INCLUDE_STRING_H) || defined(_XOS_INCLUDED_STRING_H)
0819 /* Do nothing. */
0820 
0821 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0822 /* Use regular, unsafe API. */
0823 typedef int _Xstrtokparams; /* dummy */
0824 # define _XStrtok(s1,s2,p)  strtok((s1),(s2))
0825 
0826 #elif !defined(XOS_USE_MTSAFE_STRINGAPI) || defined(XNO_MTSAFE_STRINGAPI)
0827 /* Systems with thread support but no _r API. */
0828 typedef char *_Xstrtokparams;
0829 # define _XStrtok(s1,s2,p) \
0830  ( (_Xos_processLock), \
0831    ((p) = strtok((s1),(s2))), \
0832    (_Xos_processUnlock), \
0833    (p) )
0834 
0835 #else
0836 /* POSIX or pre-POSIX API. */
0837 typedef char * _Xstrtokparams;
0838 # define _XStrtok(s1,s2,p)  strtok_r((s1),(s2),&(p))
0839 #endif /* X_INCLUDE_STRING_H */
0840 
0841 
0842 /***** <time.h> wrappers *****/
0843 
0844 /*
0845  * Effective prototypes for <time.h> wrappers:
0846  *
0847  * #define X_INCLUDE_TIME_H
0848  * #define XOS_USE_..._LOCKING
0849  * #include <X11/Xos_r.h>
0850  *
0851  * typedef ... _Xatimeparams;
0852  * typedef ... _Xctimeparams;
0853  * typedef ... _Xgtimeparams;
0854  * typedef ... _Xltimeparams;
0855  *
0856  * char *_XAsctime(const struct tm *, _Xatimeparams);
0857  * char *_XCtime(const time_t *, _Xctimeparams);
0858  * struct tm *_XGmtime(const time_t *, _Xgtimeparams);
0859  * struct tm *_XLocaltime(const time_t *, _Xltimeparams);
0860  */
0861 
0862 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
0863 # include <time.h>
0864 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_TIMEAPI)
0865 #  define XOS_USE_MTSAFE_TIMEAPI 1
0866 # endif
0867 #endif
0868 
0869 #if !defined(X_INCLUDE_TIME_H) || defined(_XOS_INCLUDED_TIME_H)
0870 /* Do nothing. */
0871 
0872 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0873 /* Use regular, unsafe API. */
0874 typedef int _Xatimeparams;  /* dummy */
0875 # define _XAsctime(t,p)     asctime((t))
0876 typedef int _Xctimeparams;  /* dummy */
0877 # define _XCtime(t,p)       ctime((t))
0878 typedef int _Xgtimeparams;  /* dummy */
0879 # define _XGmtime(t,p)      gmtime((t))
0880 typedef int _Xltimeparams;  /* dummy */
0881 # define _XLocaltime(t,p)   localtime((t))
0882 
0883 #elif !defined(XOS_USE_MTSAFE_TIMEAPI) || defined(XNO_MTSAFE_TIMEAPI)
0884 /* Systems with thread support but no _r API. */
0885 typedef struct {
0886 # ifdef TIMELEN
0887   char buf[TIMELEN];
0888 # else
0889   char buf[26];
0890 # endif
0891   char *result;
0892 } _Xctimeparams, _Xatimeparams;
0893 typedef struct {
0894   struct tm buf;
0895   struct tm *result;
0896 } _Xgtimeparams, _Xltimeparams;
0897 # define _XAsctime(t,p) \
0898  ( (_Xos_processLock), \
0899    (((p).result = asctime((t))) ? \
0900     (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
0901     0), \
0902    (_Xos_processUnlock), \
0903    (p).result )
0904 # define _XCtime(t,p) \
0905  ( (_Xos_processLock), \
0906    (((p).result = ctime((t))) ? \
0907     (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
0908     0), \
0909    (_Xos_processUnlock), \
0910    (p).result )
0911 # define _XGmtime(t,p) \
0912  ( (_Xos_processLock), \
0913    (((p).result = gmtime(t)) ? \
0914     (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
0915     0), \
0916    (_Xos_processUnlock), \
0917    (p).result )
0918 # define _XLocaltime(t,p) \
0919  ( (_Xos_processLock), \
0920    (((p).result = localtime(t)) ? \
0921     (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
0922     0), \
0923    (_Xos_processUnlock), \
0924    (p).result )
0925 
0926 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(__osf__) || defined(hpV4))
0927 /* Returns (int)0 on success.  OSF/1 v3.2, HP/UX 10
0928  *
0929  * extern int asctime_r(const struct tm *timeptr, char *buffer, int buflen);
0930  * extern int ctime_r(const time_t *timer, char *buffer, int buflen);
0931  * extern int gmtime_r(const time_t *timer, struct tm *result);
0932  * extern int localtime_r(const time_t *timer, struct tm *result);
0933  */
0934 # ifdef TIMELEN
0935 typedef char _Xatimeparams[TIMELEN];
0936 typedef char _Xctimeparams[TIMELEN];
0937 # else
0938 typedef char _Xatimeparams[26];
0939 typedef char _Xctimeparams[26];
0940 # endif
0941 typedef struct tm _Xgtimeparams;
0942 typedef struct tm _Xltimeparams;
0943 # define _XAsctime(t,p)     (asctime_r((t),(p),sizeof((p))) ? NULL : (p))
0944 # define _XCtime(t,p)       (ctime_r((t),(p),sizeof((p))) ? NULL : (p))
0945 # define _XGmtime(t,p)      (gmtime_r((t),&(p)) ? NULL : &(p))
0946 # define _XLocaltime(t,p)   (localtime_r((t),&(p)) ? NULL : &(p))
0947 
0948 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(sun)
0949 /* Returns NULL on failure.  Solaris 2.5
0950  *
0951  * extern char *asctime_r(const struct tm *tm,char *buf, int buflen);
0952  * extern char *ctime_r(const time_t *clock, char *buf, int buflen);
0953  * extern struct tm *gmtime_r(const time_t *clock, struct tm *res);
0954  * extern struct tm *localtime_r(const time_t *clock, struct tm *res);
0955  */
0956 # ifdef TIMELEN
0957 typedef char _Xatimeparams[TIMELEN];
0958 typedef char _Xctimeparams[TIMELEN];
0959 # else
0960 typedef char _Xatimeparams[26];
0961 typedef char _Xctimeparams[26];
0962 # endif
0963 typedef struct tm _Xgtimeparams;
0964 typedef struct tm _Xltimeparams;
0965 # define _XAsctime(t,p)     asctime_r((t),(p),sizeof((p)))
0966 # define _XCtime(t,p)       ctime_r((t),(p),sizeof((p)))
0967 # define _XGmtime(t,p)      gmtime_r((t),&(p))
0968 # define _XLocaltime(t,p)   localtime_r((t),&(p))
0969 
0970 #else /* defined(_POSIX_THREAD_SAFE_FUNCTIONS) */
0971 /* POSIX final API.  OSF/1 v4.0, AIX, etc.
0972  *
0973  * extern char *asctime_r(const struct tm *timeptr, char *buffer);
0974  * extern char *ctime_r(const time_t *timer, char *buffer);
0975  * extern struct tm *gmtime_r(const time_t *timer, struct tm *result);
0976  * extern struct tm *localtime_r(const time_t *timer, struct tm *result);
0977  */
0978 # if defined(__osf__)
0979 /* OSF/1 V4.0 <time.h> doesn't declare the _P routines, breaking under C++. */
0980 extern char *_Pasctime_r(const struct tm *, char *);
0981 extern char *_Pctime_r(const time_t *, char *);
0982 extern struct tm *_Plocaltime_r(const time_t *, struct tm *);
0983 # endif
0984 # ifdef TIMELEN
0985 typedef char _Xatimeparams[TIMELEN];
0986 typedef char _Xctimeparams[TIMELEN];
0987 # else
0988 typedef char _Xatimeparams[26];
0989 typedef char _Xctimeparams[26];
0990 # endif
0991 typedef struct tm _Xgtimeparams;
0992 typedef struct tm _Xltimeparams;
0993 # define _XAsctime(t,p)     asctime_r((t),(p))
0994 # define _XCtime(t,p)       ctime_r((t),(p))
0995 # define _XGmtime(t,p)      gmtime_r((t),&(p))
0996 # define _XLocaltime(t,p)   localtime_r((t),&(p))
0997 #endif /* X_INCLUDE_TIME_H */
0998 
0999 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
1000 # define _XOS_INCLUDED_TIME_H
1001 #endif
1002 
1003 
1004 /***** <grp.h> wrappers *****/
1005 
1006 /*
1007  * Effective prototypes for <grp.h> wrappers:
1008  *
1009  * NOTE: On systems lacking appropriate _r functions Getgrgid() and
1010  *  Getgrnam() do NOT copy the list of group members!
1011  *
1012  * Remember that fgetgrent(), setgrent(), getgrent(), and endgrent()
1013  * are not included in POSIX.
1014  *
1015  * #define X_INCLUDE_GRP_H
1016  * #define XOS_USE_..._LOCKING
1017  * #include <X11/Xos_r.h>
1018  *
1019  * typedef ... _Xgetgrparams;
1020  *
1021  * struct group *_XGetgrgid(gid_t, _Xgetgrparams);
1022  * struct group *_XGetgrnam(const char *, _Xgetgrparams);
1023  */
1024 
1025 #if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H)
1026 # include <grp.h>
1027 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_GRPAPI)
1028 #  define XOS_USE_MTSAFE_GRPAPI 1
1029 # endif
1030 #endif
1031 
1032 #if !defined(X_INCLUDE_GRP_H) || defined(_XOS_INCLUDED_GRP_H)
1033 /* Do nothing. */
1034 
1035 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
1036 /* Use regular, unsafe API. */
1037 typedef int _Xgetgrparams;  /* dummy */
1038 #define _XGetgrgid(g,p) getgrgid((g))
1039 #define _XGetgrnam(n,p) getgrnam((n))
1040 
1041 #elif !defined(XOS_USE_MTSAFE_GRPAPI) || defined(XNO_MTSAFE_GRPAPI)
1042 /* Systems with thread support but no _r API.  UnixWare 2.0. */
1043 typedef struct {
1044   struct group grp;
1045   char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
1046   struct group *pgrp;
1047   size_t len;
1048 } _Xgetgrparams;
1049 #ifdef SVR4
1050 /* Copy the gr_passwd field too. */
1051 # define _Xgrp_copyGroup(p) \
1052  ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \
1053    ((p).grp.gr_name = (p).buf), \
1054    ((p).len = strlen((p).pgrp->gr_name)), \
1055    strcpy((p).grp.gr_name, (p).pgrp->gr_name), \
1056    ((p).grp.gr_passwd = (p).grp.gr_name + (p).len + 1), \
1057    ((p).pgrp = &(p).grp), \
1058    0 )
1059 #else
1060 # define _Xgrp_copyGroup(p) \
1061  ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \
1062    ((p).grp.gr_name = (p).buf), \
1063    strcpy((p).grp.gr_name, (p).pgrp->gr_name), \
1064    ((p).pgrp = &(p).grp), \
1065    0 )
1066 #endif
1067 #define _XGetgrgid(g,p) \
1068  ( (_Xos_processLock), \
1069    (((p).pgrp = getgrgid((g))) ? _Xgrp_copyGroup(p) : 0), \
1070    (_Xos_processUnlock), \
1071    (p).pgrp )
1072 #define _XGetgrnam(n,p) \
1073  ( (_Xos_processLock), \
1074    (((p).pgrp = getgrnam((n))) ? _Xgrp_copyGroup(p) : 0), \
1075    (_Xos_processUnlock), \
1076    (p).pgrp )
1077 
1078 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(sun) || defined(__osf__))
1079 /* Non-POSIX API.  Solaris, DEC v3.2.
1080  *
1081  * extern struct group *getgrgid_r(gid_t, struct group *, char *, int);
1082  * extern struct group *getgrnam_r(const char *, struct group *, char *, int);
1083  */
1084 typedef struct {
1085   struct group grp;
1086   char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
1087 } _Xgetgrparams;
1088 #define _XGetgrgid(g,p) getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf))
1089 #define _XGetgrnam(n,p) getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf))
1090 
1091 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
1092 /* Non-POSIX API.  HP/UX 10, AIX 4.
1093  *
1094  * extern int getgrgid_r(gid_t, struct group *, char *, int);
1095  * extern int getgrnam_r(const char *, struct group *, char *, int);
1096  */
1097 typedef struct {
1098   struct group grp;
1099   char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
1100 } _Xgetgrparams;
1101 #define _XGetgrgid(g,p) \
1102  ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp))
1103 #define _XGetgrnam(n,p) \
1104  ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp))
1105 
1106 #else
1107 /* POSIX final API.  DEC v4.0, IRIX 6.2.
1108  *
1109  * int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
1110  * int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
1111  */
1112 # if defined(__osf__)
1113 /* OSF/1 V4.0 <grp.h> doesn't declare the _P routines, breaking under C++. */
1114 extern int _Pgetgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
1115 extern int _Pgetgrnam_r(const char *, struct group *, char *, size_t, struct group **);
1116 # endif
1117 typedef struct {
1118   struct group grp;
1119   char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
1120   struct group *result;
1121 } _Xgetgrparams;
1122 
1123 #define _XGetgrgid(g,p) \
1124  ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \
1125    NULL : (p).result))
1126 #define _XGetgrnam(n,p) \
1127  ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \
1128    NULL : (p).result))
1129 #endif
1130 
1131 #if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H)
1132 # define _XOS_INCLUDED_GRP_H
1133 #endif
1134 
1135 
1136 #ifdef __cplusplus
1137 }  /* Close scope of 'extern "C"' declaration which encloses file. */
1138 #endif