1 /* DO NOT EDIT THIS FILE. 2 3 It has been auto-edited by fixincludes from: 4 5 "/usr/include/X11/Xos_r.h" 6 7 This had to be done to correct non-standard usages in the 8 original, manufacturer supplied header file. */ 9 10 /* $Xorg: Xos_r.h,v 1.4 2001/02/09 02:03:22 xorgcvs Exp $ */ 11 /* $XdotOrg: xc/include/Xos_r.h,v 1.4 2005/03/02 19:29:31 alanc Exp $ */ 12 /* 13 Copyright 1996, 1998 The Open Group 14 15 Permission to use, copy, modify, distribute, and sell this software and its 16 documentation for any purpose is hereby granted without fee, provided that 17 the above copyright notice appear in all copies and that both that 18 copyright notice and this permission notice appear in supporting 19 documentation. 20 21 The above copyright notice and this permission notice shall be included in 22 all copies or substantial portions of the Software. 23 24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 31 Except as contained in this notice, the name of The Open Group shall not be 32 used in advertising or otherwise to promote the sale, use or other dealings 33 in this Software without prior written authorization from The Open Group. 34 */ 35 /* $XFree86: xc/include/Xos_r.h,v 1.18tsi Exp $ */ 36 37 /* 38 * Various and sundry Thread-Safe functions used by X11, Motif, and CDE. 39 * 40 * Use this file in MT-safe code where you would have included 41 * <dirent.h> for readdir() 42 * <grp.h> for getgrgid() or getgrnam() 43 * <netdb.h> for gethostbyname(), gethostbyaddr(), or getservbyname() 44 * <pwd.h> for getpwnam() or getpwuid() 45 * <string.h> for strtok() 46 * <time.h> for asctime(), ctime(), localtime(), or gmtime() 47 * <unistd.h> for getlogin() or ttyname() 48 * or their thread-safe analogs. 49 * 50 * If you are on a platform that defines XTHREADS but does not have 51 * MT-safe system API (e.g. UnixWare) you must define _Xos_processLock 52 * and _Xos_processUnlock macros before including this header. If 53 * you are on OSF/1 V3.2 and plan to use readdir(), you must also define 54 * _Xos_isThreadsInitialized. For convenience XOS_USE_XLIB_LOCKING or 55 * XOS_USE_XT_LOCKING may be defined to obtain either Xlib-only or 56 * Xt-based versions of these macros. These macros won't result in 57 * truly thread-safe calls, but they are better than nothing. If you 58 * do not want locking in this situation define XOS_USE_NO_LOCKING. 59 * 60 * NOTE: On systems lacking approriate _r functions Gethostbyname(), 61 * Gethostbyaddr(), and Getservbyname() do NOT copy the host or 62 * protocol lists! 63 * 64 * NOTE: On systems lacking appropriate _r functions Getgrgid() and 65 * Getgrnam() do NOT copy the list of group members! 66 * 67 * This header is nominally intended to simplify porting X11, Motif, and 68 * CDE; it may be useful to other people too. The structure below is 69 * complicated, mostly because P1003.1c (the IEEE POSIX Threads spec) 70 * went through lots of drafts, and some vendors shipped systems based 71 * on draft API that were changed later. Unfortunately POSIX did not 72 * provide a feature-test macro for distinguishing each of the drafts. 73 */ 74 75 /* 76 * This header has several parts. Search for "Effective prototypes" 77 * to locate the beginning of a section. 78 */ 79 80 /* This header can be included multiple times with different defines! */ 81 #ifndef _XOS_R_H_ 82 # define _XOS_R_H_ 83 84 # include <X11/Xos.h> 85 # include <X11/Xfuncs.h> 86 87 # ifndef X_NOT_POSIX 88 # ifdef _POSIX_SOURCE 89 # include <limits.h> 90 # else 91 # define _POSIX_SOURCE 92 # include <limits.h> 93 # undef _POSIX_SOURCE 94 # endif 95 # ifndef LINE_MAX 96 # define X_LINE_MAX 2048 97 # else 98 # define X_LINE_MAX LINE_MAX 99 # endif 100 # endif 101 #endif /* _XOS_R_H */ 102 103 #ifndef WIN32 104 105 #ifdef __cplusplus 106 extern "C" { 107 #endif 108 109 # if defined(XOS_USE_XLIB_LOCKING) 110 # ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 111 typedef struct _LockInfoRec *LockInfoPtr; 112 extern LockInfoPtr _Xglobal_lock; 113 # endif 114 # ifndef _Xos_isThreadInitialized 115 # define _Xos_isThreadInitialized (_Xglobal_lock) 116 # endif 117 # if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 118 # ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 119 # include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 120 extern void (*_XLockMutex_fn)( 121 # if NeedFunctionPrototypes 122 LockInfoPtr /* lock */, char * /* file */, int /* line */ 123 # endif 124 ); 125 extern void (*_XUnlockMutex_fn)( 126 # if NeedFunctionPrototypes 127 LockInfoPtr /* lock */, char * /* file */, int /* line */ 128 # endif 129 ); 130 # endif 131 # ifndef _Xos_processLock 132 # define _Xos_processLock \ 133 (_XLockMutex_fn ? (*_XLockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0) 134 # endif 135 # ifndef _Xos_processUnlock 136 # define _Xos_processUnlock \ 137 (_XUnlockMutex_fn ? (*_XUnlockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0) 138 # endif 139 # else 140 # ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */ 141 # include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 142 extern void (*_XLockMutex_fn)( 143 # if NeedFunctionPrototypes 144 LockInfoPtr /* lock */ 145 # endif 146 ); 147 extern void (*_XUnlockMutex_fn)( 148 # if NeedFunctionPrototypes 149 LockInfoPtr /* lock */ 150 # endif 151 ); 152 # endif 153 # ifndef _Xos_processLock 154 # define _Xos_processLock \ 155 (_XLockMutex_fn ? ((*_XLockMutex_fn)(_Xglobal_lock), 0) : 0) 156 # endif 157 # ifndef _Xos_processUnlock 158 # define _Xos_processUnlock \ 159 (_XUnlockMutex_fn ? ((*_XUnlockMutex_fn)(_Xglobal_lock), 0) : 0) 160 # endif 161 # endif 162 # elif defined(XOS_USE_XT_LOCKING) 163 # ifndef _XtThreadsI_h 164 extern void (*_XtProcessLock)(void); 165 # endif 166 # ifndef _XtintrinsicP_h 167 # include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */ 168 extern void XtProcessLock( 169 # if NeedFunctionPrototypes 170 void 171 # endif 172 ); 173 extern void XtProcessUnlock( 174 # if NeedFunctionPrototypes 175 void 176 # endif 177 ); 178 # endif 179 # ifndef _Xos_isThreadInitialized 180 # define _Xos_isThreadInitialized _XtProcessLock 181 # endif 182 # ifndef _Xos_processLock 183 # define _Xos_processLock XtProcessLock() 184 # endif 185 # ifndef _Xos_processUnlock 186 # define _Xos_processUnlock XtProcessUnlock() 187 # endif 188 # elif defined(XOS_USE_NO_LOCKING) 189 # ifndef _Xos_isThreadInitialized 190 # define _Xos_isThreadInitialized 0 191 # endif 192 # ifndef _Xos_processLock 193 # define _Xos_processLock 0 194 # endif 195 # ifndef _Xos_processUnlock 196 # define _Xos_processUnlock 0 197 # endif 198 # endif 199 200 #endif /* !defined WIN32 */ 201 202 /* 203 * Solaris defines the POSIX thread-safe feature test macro, but 204 * uses the older SVR4 thread-safe functions unless the POSIX ones 205 * are specifically requested. Fix the feature test macro. 206 */ 207 #if defined(sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && \ 208 (_POSIX_C_SOURCE - 0 < 199506L) && !defined(_POSIX_PTHREAD_SEMANTICS) 209 # undef _POSIX_THREAD_SAFE_FUNCTIONS 210 #endif 211 212 /* 213 * LynxOS 3.1 defines _POSIX_THREAD_SAFE_FUNCTIONS but 214 * getpwuid_r has different semantics than defined by POSIX 215 */ 216 #if defined(Lynx) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) 217 # undef _POSIX_THREAD_SAFE_FUNCTIONS 218 #endif 219 220 221 /***** <pwd.h> wrappers *****/ 222 223 /* 224 * Effective prototypes for <pwd.h> wrappers: 225 * 226 * #define X_INCLUDE_PWD_H 227 * #define XOS_USE_..._LOCKING 228 * #include <X11/Xos_r.h> 229 * 230 * typedef ... _Xgetpwparams; 231 * 232 * struct passwd* _XGetpwnam(const char *name, _Xgetpwparams); 233 * struct passwd* _XGetpwuid(uid_t uid, _Xgetpwparams); 234 */ 235 236 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H) 237 # include <pwd.h> 238 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI) 239 # define XOS_USE_MTSAFE_PWDAPI 1 240 # endif 241 #endif 242 243 #undef X_NEEDS_PWPARAMS 244 #if !defined(X_INCLUDE_PWD_H) || defined(_XOS_INCLUDED_PWD_H) 245 /* Do nothing */ 246 247 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 248 /* Use regular, unsafe API. */ 249 # if defined(X_NOT_POSIX) && !defined(__i386__) && !defined(SYSV) 250 extern struct passwd *getpwuid(), *getpwnam(); 251 # endif 252 typedef int _Xgetpwparams; /* dummy */ 253 # define _XGetpwuid(u,p) getpwuid((u)) 254 # define _XGetpwnam(u,p) getpwnam((u)) 255 256 #elif !defined(XOS_USE_MTSAFE_PWDAPI) || defined(XNO_MTSAFE_PWDAPI) 257 /* UnixWare 2.0, or other systems with thread support but no _r API. */ 258 # define X_NEEDS_PWPARAMS 259 typedef struct { 260 struct passwd pws; 261 char pwbuf[1024]; 262 struct passwd* pwp; 263 size_t len; 264 } _Xgetpwparams; 265 266 /* 267 * NetBSD and FreeBSD, at least, are missing several of the unixware passwd 268 * fields. 269 */ 270 271 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 272 defined(__APPLE__) || defined(__DragonFly__) 273 static __inline__ void _Xpw_copyPasswd(_Xgetpwparams p) 274 { 275 memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)); 276 277 (p).pws.pw_name = (p).pwbuf; 278 (p).len = strlen((p).pwp->pw_name); 279 strcpy((p).pws.pw_name, (p).pwp->pw_name); 280 281 (p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1; 282 (p).len = strlen((p).pwp->pw_passwd); 283 strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd); 284 285 (p).pws.pw_class = (p).pws.pw_passwd + (p).len + 1; 286 (p).len = strlen((p).pwp->pw_class); 287 strcpy((p).pws.pw_class, (p).pwp->pw_class); 288 289 (p).pws.pw_gecos = (p).pws.pw_class + (p).len + 1; 290 (p).len = strlen((p).pwp->pw_gecos); 291 strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos); 292 293 (p).pws.pw_dir = (p).pws.pw_gecos + (p).len + 1; 294 (p).len = strlen((p).pwp->pw_dir); 295 strcpy((p).pws.pw_dir, (p).pwp->pw_dir); 296 297 (p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1; 298 (p).len = strlen((p).pwp->pw_shell); 299 strcpy((p).pws.pw_shell, (p).pwp->pw_shell); 300 301 (p).pwp = &(p).pws; 302 } 303 304 #else 305 # define _Xpw_copyPasswd(p) \ 306 (memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)), \ 307 ((p).pws.pw_name = (p).pwbuf), \ 308 ((p).len = strlen((p).pwp->pw_name)), \ 309 strcpy((p).pws.pw_name, (p).pwp->pw_name), \ 310 ((p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1), \ 311 ((p).len = strlen((p).pwp->pw_passwd)), \ 312 strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd), \ 313 ((p).pws.pw_age = (p).pws.pw_passwd + (p).len + 1), \ 314 ((p).len = strlen((p).pwp->pw_age)), \ 315 strcpy((p).pws.pw_age, (p).pwp->pw_age), \ 316 ((p).pws.pw_comment = (p).pws.pw_age + (p).len + 1), \ 317 ((p).len = strlen((p).pwp->pw_comment)), \ 318 strcpy((p).pws.pw_comment, (p).pwp->pw_comment), \ 319 ((p).pws.pw_gecos = (p).pws.pw_comment + (p).len + 1), \ 320 ((p).len = strlen((p).pwp->pw_gecos)), \ 321 strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos), \ 322 ((p).pws.pw_dir = (p).pws.pw_comment + (p).len + 1), \ 323 ((p).len = strlen((p).pwp->pw_dir)), \ 324 strcpy((p).pws.pw_dir, (p).pwp->pw_dir), \ 325 ((p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1), \ 326 ((p).len = strlen((p).pwp->pw_shell)), \ 327 strcpy((p).pws.pw_shell, (p).pwp->pw_shell), \ 328 ((p).pwp = &(p).pws), \ 329 0 ) 330 #endif 331 # define _XGetpwuid(u,p) \ 332 ( (_Xos_processLock), \ 333 (((p).pwp = getpwuid((u))) ? _Xpw_copyPasswd(p), 0 : 0), \ 334 (_Xos_processUnlock), \ 335 (p).pwp ) 336 # define _XGetpwnam(u,p) \ 337 ( (_Xos_processLock), \ 338 (((p).pwp = getpwnam((u))) ? _Xpw_copyPasswd(p), 0 : 0), \ 339 (_Xos_processUnlock), \ 340 (p).pwp ) 341 342 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__) 343 /* SVR4 threads, AIX 4.2.0 and earlier and OSF/1 3.2 and earlier pthreads */ 344 # define X_NEEDS_PWPARAMS 345 typedef struct { 346 struct passwd pws; 347 char pwbuf[X_LINE_MAX]; 348 } _Xgetpwparams; 349 # if defined(_POSIX_REENTRANT_FUNCTIONS) || !defined(SVR4) || defined(Lynx) 350 # ifndef Lynx 351 # define _XGetpwuid(u,p) \ 352 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 353 # define _XGetpwnam(u,p) \ 354 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 355 # else /* Lynx */ 356 # define _XGetpwuid(u,p) \ 357 ((getpwuid_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 358 # define _XGetpwnam(u,p) \ 359 ((getpwnam_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws) 360 # endif 361 # else /* SVR4 */ 362 # define _XGetpwuid(u,p) \ 363 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws) 364 # define _XGetpwnam(u,p) \ 365 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws) 366 # endif /* SVR4 */ 367 368 #else /* _POSIX_THREAD_SAFE_FUNCTIONS */ 369 /* Digital UNIX 4.0, but not (beta) T4.0-1 */ 370 # if defined(__osf__) 371 /* OSF/1 V4.0 <pwd.h> doesn't declare the _P routines, breaking under C++. */ 372 extern int _Pgetpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); 373 extern int _Pgetpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); 374 # endif 375 # define X_NEEDS_PWPARAMS 376 typedef struct { 377 struct passwd pws; 378 char pwbuf[X_LINE_MAX]; 379 struct passwd* pwp; 380 } _Xgetpwparams; 381 typedef int _Xgetpwret; 382 # define _XGetpwuid(u,p) \ 383 ((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == 0) ? \ 384 (p).pwp : NULL) 385 # define _XGetpwnam(u,p) \ 386 ((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == 0) ? \ 387 (p).pwp : NULL) 388 #endif /* X_INCLUDE_PWD_H */ 389 390 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H) 391 # define _XOS_INCLUDED_PWD_H 392 #endif 393 394 395 /***** <netdb.h> wrappers *****/ 396 397 /* 398 * Effective prototypes for <netdb.h> wrappers: 399 * 400 * NOTE: On systems lacking the appropriate _r functions Gethostbyname(), 401 * Gethostbyaddr(), and Getservbyname() do NOT copy the host or 402 * protocol lists! 403 * 404 * #define X_INCLUDE_NETDB_H 405 * #define XOS_USE_..._LOCKING 406 * #include <X11/Xos_r.h> 407 * 408 * typedef ... _Xgethostbynameparams; 409 * typedef ... _Xgetservbynameparams; 410 * 411 * struct hostent* _XGethostbyname(const char* name,_Xgethostbynameparams); 412 * struct hostent* _XGethostbyaddr(const char* addr, int len, int type, 413 * _Xgethostbynameparams); 414 * struct servent* _XGetservbyname(const char* name, const char* proto, 415 * _Xgetservbynameparams); 416 */ 417 418 #undef XTHREADS_NEEDS_BYNAMEPARAMS 419 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \ 420 && !defined(WIN32) 421 # include <netdb.h> 422 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI) 423 # define XOS_USE_MTSAFE_NETDBAPI 1 424 # endif 425 #endif 426 427 #if !defined(X_INCLUDE_NETDB_H) || defined(_XOS_INCLUDED_NETDB_H) 428 /* Do nothing. */ 429 430 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 431 /* Use regular, unsafe API. */ 432 typedef int _Xgethostbynameparams; /* dummy */ 433 typedef int _Xgetservbynameparams; /* dummy */ 434 # define _XGethostbyname(h,hp) gethostbyname((h)) 435 # define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t)) 436 # define _XGetservbyname(s,p,sp) getservbyname((s),(p)) 437 438 #elif !defined(XOS_USE_MTSAFE_NETDBAPI) || defined(XNO_MTSAFE_NETDBAPI) 439 /* UnixWare 2.0, or other systems with thread support but no _r API. */ 440 /* WARNING: The h_addr_list and s_aliases values are *not* copied! */ 441 442 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) 443 #include <sys/param.h> 444 #endif 445 446 typedef struct { 447 struct hostent hent; 448 char h_name[MAXHOSTNAMELEN]; 449 struct hostent *hptr; 450 } _Xgethostbynameparams; 451 typedef struct { 452 struct servent sent; 453 char s_name[255]; 454 char s_proto[255]; 455 struct servent *sptr; 456 } _Xgetservbynameparams; 457 458 # define XTHREADS_NEEDS_BYNAMEPARAMS 459 460 # define _Xg_copyHostent(hp) \ 461 (memcpy(&(hp).hent, (hp).hptr, sizeof(struct hostent)), \ 462 strcpy((hp).h_name, (hp).hptr->h_name), \ 463 ((hp).hent.h_name = (hp).h_name), \ 464 ((hp).hptr = &(hp).hent), \ 465 0 ) 466 # define _Xg_copyServent(sp) \ 467 (memcpy(&(sp).sent, (sp).sptr, sizeof(struct servent)), \ 468 strcpy((sp).s_name, (sp).sptr->s_name), \ 469 ((sp).sent.s_name = (sp).s_name), \ 470 strcpy((sp).s_proto, (sp).sptr->s_proto), \ 471 ((sp).sent.s_proto = (sp).s_proto), \ 472 ((sp).sptr = &(sp).sent), \ 473 0 ) 474 # define _XGethostbyname(h,hp) \ 475 ((_Xos_processLock), \ 476 (((hp).hptr = gethostbyname((h))) ? _Xg_copyHostent(hp) : 0), \ 477 (_Xos_processUnlock), \ 478 (hp).hptr ) 479 # define _XGethostbyaddr(a,al,t,hp) \ 480 ((_Xos_processLock), \ 481 (((hp).hptr = gethostbyaddr((a),(al),(t))) ? _Xg_copyHostent(hp) : 0), \ 482 (_Xos_processUnlock), \ 483 (hp).hptr ) 484 # define _XGetservbyname(s,p,sp) \ 485 ((_Xos_processLock), \ 486 (((sp).sptr = getservbyname((s),(p))) ? _Xg_copyServent(sp) : 0), \ 487 (_Xos_processUnlock), \ 488 (sp).sptr ) 489 490 #elif defined(XUSE_NETDB_R_API) 491 /* 492 * POSIX does not specify _r equivalents for <netdb.h> API, but some 493 * vendors provide them anyway. Use them only when explicitly asked. 494 */ 495 # ifdef _POSIX_REENTRANT_FUNCTIONS 496 # ifndef _POSIX_THREAD_SAFE_FUNCTIONS 497 # if defined(AIXV3) || defined(AIXV4) || defined(__osf__) 498 # define X_POSIX_THREAD_SAFE_FUNCTIONS 1 499 # endif 500 # endif 501 # endif 502 # ifdef _POSIX_THREAD_SAFE_FUNCTIONS 503 # define X_POSIX_THREAD_SAFE_FUNCTIONS 1 504 # endif 505 506 # define XTHREADS_NEEDS_BYNAMEPARAMS 507 508 # ifndef X_POSIX_THREAD_SAFE_FUNCTIONS 509 typedef struct { 510 struct hostent hent; 511 char hbuf[X_LINE_MAX]; 512 int herr; 513 } _Xgethostbynameparams; 514 typedef struct { 515 struct servent sent; 516 char sbuf[X_LINE_MAX]; 517 } _Xgetservbynameparams; 518 # define _XGethostbyname(h,hp) \ 519 gethostbyname_r((h),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr) 520 # define _XGethostbyaddr(a,al,t,hp) \ 521 gethostbyaddr_r((a),(al),(t),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr) 522 # define _XGetservbyname(s,p,sp) \ 523 getservbyname_r((s),(p),&(sp).sent,(sp).sbuf,sizeof((sp).sbuf)) 524 # else 525 typedef struct { 526 struct hostent hent; 527 struct hostent_data hdata; 528 } _Xgethostbynameparams; 529 typedef struct { 530 struct servent sent; 531 struct servent_data sdata; 532 } _Xgetservbynameparams; 533 # define _XGethostbyname(h,hp) \ 534 (bzero((char*)&(hp).hdata,sizeof((hp).hdata)), \ 535 ((gethostbyname_r((h),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent)) 536 # define _XGethostbyaddr(a,al,t,hp) \ 537 (bzero((char*)&(hp).hdata,sizeof((hp).hdata)), \ 538 ((gethostbyaddr_r((a),(al),(t),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent)) 539 # define _XGetservbyname(s,p,sp) \ 540 (bzero((char*)&(sp).sdata,sizeof((sp).sdata)), \ 541 ((getservbyname_r((s),(p),&(sp).sent,&(sp).sdata) == -1) ? NULL : &(sp).sent) ) 542 # endif 543 # ifdef X_POSIX_THREAD_SAFE_FUNCTIONS 544 # undef X_POSIX_THREAD_SAFE_FUNCTIONS 545 # endif 546 547 #else 548 /* The regular API is assumed to be MT-safe under POSIX. */ 549 typedef int _Xgethostbynameparams; /* dummy */ 550 typedef int _Xgetservbynameparams; /* dummy */ 551 # define _XGethostbyname(h,hp) gethostbyname((h)) 552 # define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t)) 553 # define _XGetservbyname(s,p,sp) getservbyname((s),(p)) 554 #endif /* X_INCLUDE_NETDB_H */ 555 556 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) 557 # define _XOS_INCLUDED_NETDB_H 558 #endif 559 560 561 /***** <dirent.h> wrappers *****/ 562 563 /* 564 * Effective prototypes for <dirent.h> wrappers: 565 * 566 * #define X_INCLUDE_DIRENT_H 567 * #define XOS_USE_..._LOCKING 568 * #include <X11/Xos_r.h> 569 * 570 * typedef ... _Xreaddirparams; 571 * 572 * struct dirent *_XReaddir(DIR *dir_pointer, _Xreaddirparams); 573 */ 574 575 #if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H) 576 # include <sys/types.h> 577 # if !defined(X_NOT_POSIX) || defined(SYSV) || defined(USG) 578 # include <dirent.h> 579 # else 580 # include <sys/dir.h> 581 # ifndef dirent 582 # define dirent direct 583 # endif 584 # endif 585 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_DIRENTAPI) 586 # define XOS_USE_MTSAFE_DIRENTAPI 1 587 # endif 588 #endif 589 590 #if !defined(X_INCLUDE_DIRENT_H) || defined(_XOS_INCLUDED_DIRENT_H) 591 /* Do nothing. */ 592 593 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 594 /* Use regular, unsafe API. */ 595 typedef int _Xreaddirparams; /* dummy */ 596 # define _XReaddir(d,p) readdir(d) 597 598 #elif !defined(XOS_USE_MTSAFE_DIRENTAPI) || defined(XNO_MTSAFE_DIRENTAPI) 599 /* Systems with thread support but no _r API. */ 600 typedef struct { 601 struct dirent *result; 602 struct dirent dir_entry; 603 # ifdef _POSIX_PATH_MAX 604 char buf[_POSIX_PATH_MAX]; 605 # elif defined(NAME_MAX) 606 char buf[NAME_MAX]; 607 # else 608 char buf[255]; 609 # endif 610 } _Xreaddirparams; 611 612 # define _XReaddir(d,p) \ 613 ( (_Xos_processLock), \ 614 (((p).result = readdir((d))) ? \ 615 (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \ 616 ((p).result = &(p).dir_entry), 0) : \ 617 0), \ 618 (_Xos_processUnlock), \ 619 (p).result ) 620 621 #else 622 typedef struct { 623 struct dirent *result; 624 struct dirent dir_entry; 625 # ifdef _POSIX_PATH_MAX 626 char buf[_POSIX_PATH_MAX]; 627 # elif defined(NAME_MAX) 628 char buf[NAME_MAX]; 629 # else 630 char buf[255]; 631 # endif 632 } _Xreaddirparams; 633 634 # if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(AIXV3) || \ 635 defined(AIXV4) || defined(__APPLE__) 636 /* AIX defines the draft POSIX symbol, but uses the final API. */ 637 /* POSIX final API, returns (int)0 on success. */ 638 # if defined(__osf__) 639 /* OSF/1 V4.0 <dirent.h> doesn't declare _Preaddir_r, breaking under C++. */ 640 extern int _Preaddir_r(DIR *, struct dirent *, struct dirent **); 641 # endif 642 # define _XReaddir(d,p) \ 643 (readdir_r((d), &((p).dir_entry), &((p).result)) ? NULL : (p).result) 644 # elif defined(_POSIX_REENTRANT_FUNCTIONS) && defined(__osf__) 645 /* 646 * OSF/1 V3.2 readdir_r() will SEGV if the main program is not 647 * explicitly linked with -lc_r. The library REQUIREDLIBS don't help. 648 * Assume that if threads have been initialized we're linked properly. 649 */ 650 # define _XReaddir(d,p) \ 651 ( (_Xos_isThreadInitialized) ? \ 652 (readdir_r((d), &((p).dir_entry)) ? NULL : &((p).dir_entry)) : \ 653 ((_Xos_processLock), \ 654 (((p).result = readdir((d))) ? \ 655 (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \ 656 ((p).result = &(p).dir_entry), 0) : \ 657 0), \ 658 (_Xos_processUnlock), \ 659 (p).result) ) 660 # elif defined(_POSIX_REENTRANT_FUNCTIONS) 661 /* POSIX draft API, returns (int)0 on success. */ 662 # define _XReaddir(d,p) \ 663 (readdir_r((d),&((p).dir_entry)) ? NULL : &((p).dir_entry)) 664 # elif defined(SVR4) 665 /* Pre-POSIX API, returns non-NULL on success. */ 666 # define _XReaddir(d,p) (readdir_r((d), &(p).dir_entry)) 667 # else 668 /* We have no idea what is going on. Fake it all using process locks. */ 669 # define _XReaddir(d,p) \ 670 ( (_Xos_processLock), \ 671 (((p).result = readdir((d))) ? \ 672 (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \ 673 ((p).result = &(p).dir_entry), 0) : \ 674 0), \ 675 (_Xos_processUnlock), \ 676 (p).result ) 677 # endif 678 #endif /* X_INCLUDE_DIRENT_H */ 679 680 #if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H) 681 # define _XOS_INCLUDED_DIRENT_H 682 #endif 683 684 685 /***** <unistd.h> wrappers *****/ 686 687 /* 688 * Effective prototypes for <unistd.h> wrappers: 689 * 690 * #define X_INCLUDE_UNISTD_H 691 * #define XOS_USE_..._LOCKING 692 * #include <X11/Xos_r.h> 693 * 694 * typedef ... _Xgetloginparams; 695 * typedef ... _Xttynameparams; 696 * 697 * char *_XGetlogin(_Xgetloginparams); 698 * char *_XTtyname(int, _Xttynameparams); 699 */ 700 701 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H) 702 /* <unistd.h> already included by <X11/Xos.h> */ 703 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_UNISTDAPI) 704 # define XOS_USE_MTSAFE_UNISTDAPI 1 705 # endif 706 #endif 707 708 #if !defined(X_INCLUDE_UNISTD_H) || defined(_XOS_INCLUDED_UNISTD_H) 709 /* Do nothing. */ 710 711 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 712 /* Use regular, unsafe API. */ 713 typedef int _Xgetloginparams; /* dummy */ 714 typedef int _Xttynameparams; /* dummy */ 715 # define _XGetlogin(p) getlogin() 716 # define _XTtyname(f) ttyname((f)) 717 718 #elif !defined(XOS_USE_MTSAFE_UNISTDAPI) || defined(XNO_MTSAFE_UNISTDAPI) 719 /* Systems with thread support but no _r API. */ 720 typedef struct { 721 char *result; 722 # if defined(MAXLOGNAME) 723 char buf[MAXLOGNAME]; 724 # elif defined(LOGIN_NAME_MAX) 725 char buf[LOGIN_NAME_MAX]; 726 # else 727 char buf[64]; 728 # endif 729 } _Xgetloginparams; 730 typedef struct { 731 char *result; 732 # ifdef TTY_NAME_MAX 733 char buf[TTY_NAME_MAX]; 734 # elif defined(_POSIX_TTY_NAME_MAX) 735 char buf[_POSIX_TTY_NAME_MAX]; 736 # elif defined(_POSIX_PATH_MAX) 737 char buf[_POSIX_PATH_MAX]; 738 # else 739 char buf[256]; 740 # endif 741 } _Xttynameparams; 742 743 # define _XGetlogin(p) \ 744 ( (_Xos_processLock), \ 745 (((p).result = getlogin()) ? \ 746 (strncpy((p).buf, (p).result, sizeof((p).buf)), \ 747 ((p).buf[sizeof((p).buf)-1] = '\0'), \ 748 ((p).result = (p).buf), 0) : 0), \ 749 (_Xos_processUnlock), \ 750 (p).result ) 751 #define _XTtyname(f,p) \ 752 ( (_Xos_processLock), \ 753 (((p).result = ttyname(f)) ? \ 754 (strncpy((p).buf, (p).result, sizeof((p).buf)), \ 755 ((p).buf[sizeof((p).buf)-1] = '\0'), \ 756 ((p).result = (p).buf), 0) : 0), \ 757 (_Xos_processUnlock), \ 758 (p).result ) 759 760 #elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_POSIX_REENTRANT_FUNCTIONS) 761 /* POSIX API. 762 * 763 * extern int getlogin_r(char *, size_t); 764 * extern int ttyname_r(int, char *, size_t); 765 */ 766 typedef struct { 767 # if defined(MAXLOGNAME) 768 char buf[MAXLOGNAME]; 769 # elif defined(LOGIN_NAME_MAX) 770 char buf[LOGIN_NAME_MAX]; 771 # else 772 char buf[64]; 773 # endif 774 } _Xgetloginparams; 775 typedef struct { 776 # ifdef TTY_NAME_MAX 777 char buf[TTY_NAME_MAX]; 778 # elif defined(_POSIX_TTY_NAME_MAX) 779 char buf[_POSIX_TTY_NAME_MAX]; 780 # elif defined(_POSIX_PATH_MAX) 781 char buf[_POSIX_PATH_MAX]; 782 # else 783 char buf[256]; 784 # endif 785 } _Xttynameparams; 786 787 # define _XGetlogin(p) (getlogin_r((p).buf, sizeof((p).buf)) ? NULL : (p).buf) 788 # define _XTtyname(f,p) \ 789 (ttyname_r((f), (p).buf, sizeof((p).buf)) ? NULL : (p).buf) 790 791 #else 792 /* Pre-POSIX API. 793 * 794 * extern char *getlogin_r(char *, size_t); 795 * extern char *ttyname_r(int, char *, size_t); 796 */ 797 typedef struct { 798 # if defined(MAXLOGNAME) 799 char buf[MAXLOGNAME]; 800 # elif defined(LOGIN_NAME_MAX) 801 char buf[LOGIN_NAME_MAX]; 802 # else 803 char buf[64]; 804 # endif 805 } _Xgetloginparams; 806 typedef struct { 807 # ifdef TTY_NAME_MAX 808 char buf[TTY_NAME_MAX]; 809 # elif defined(_POSIX_TTY_NAME_MAX) 810 char buf[_POSIX_TTY_NAME_MAX]; 811 # elif defined(_POSIX_PATH_MAX) 812 char buf[_POSIX_PATH_MAX]; 813 # else 814 char buf[256]; 815 # endif 816 } _Xttynameparams; 817 818 # define _XGetlogin(p) getlogin_r((p).buf, sizeof((p).buf)) 819 # define _XTtyname(f,p) ttyname_r((f), (p).buf, sizeof((p).buf)) 820 #endif /* X_INCLUDE_UNISTD_H */ 821 822 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H) 823 # define _XOS_INCLUDED_UNISTD_H 824 #endif 825 826 827 /***** <string.h> wrappers *****/ 828 829 /* 830 * Effective prototypes for <string.h> wrappers: 831 * 832 * #define X_INCLUDE_STRING_H 833 * #define XOS_USE_..._LOCKING 834 * #include <X11/Xos_r.h> 835 * 836 * typedef ... _Xstrtokparams; 837 * 838 * char *_XStrtok(char *, const char*, _Xstrtokparams); 839 */ 840 841 #if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H) 842 /* <string.h> has already been included by <X11/Xos.h> */ 843 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_STRINGAPI) 844 # define XOS_USE_MTSAFE_STRINGAPI 1 845 # endif 846 #endif 847 848 #if !defined(X_INCLUDE_STRING_H) || defined(_XOS_INCLUDED_STRING_H) 849 /* Do nothing. */ 850 851 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 852 /* Use regular, unsafe API. */ 853 typedef int _Xstrtokparams; /* dummy */ 854 # define _XStrtok(s1,s2,p) \ 855 ( p = 0, (void)p, strtok((s1),(s2)) ) 856 857 #elif !defined(XOS_USE_MTSAFE_STRINGAPI) || defined(XNO_MTSAFE_STRINGAPI) 858 /* Systems with thread support but no _r API. */ 859 typedef char *_Xstrtokparams; 860 # define _XStrtok(s1,s2,p) \ 861 ( (_Xos_processLock), \ 862 ((p) = strtok((s1),(s2))), \ 863 (_Xos_processUnlock), \ 864 (p) ) 865 866 #else 867 /* POSIX or pre-POSIX API. */ 868 typedef char * _Xstrtokparams; 869 # define _XStrtok(s1,s2,p) strtok_r((s1),(s2),&(p)) 870 #endif /* X_INCLUDE_STRING_H */ 871 872 873 /***** <time.h> wrappers *****/ 874 875 /* 876 * Effective prototypes for <time.h> wrappers: 877 * 878 * #define X_INCLUDE_TIME_H 879 * #define XOS_USE_..._LOCKING 880 * #include <X11/Xos_r.h> 881 * 882 * typedef ... _Xatimeparams; 883 * typedef ... _Xctimeparams; 884 * typedef ... _Xgtimeparams; 885 * typedef ... _Xltimeparams; 886 * 887 * char *_XAsctime(const struct tm *, _Xatimeparams); 888 * char *_XCtime(const time_t *, _Xctimeparams); 889 * struct tm *_XGmtime(const time_t *, _Xgtimeparams); 890 * struct tm *_XLocaltime(const time_t *, _Xltimeparams); 891 */ 892 893 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H) 894 # include <time.h> 895 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_TIMEAPI) 896 # define XOS_USE_MTSAFE_TIMEAPI 1 897 # endif 898 #endif 899 900 #if !defined(X_INCLUDE_TIME_H) || defined(_XOS_INCLUDED_TIME_H) 901 /* Do nothing. */ 902 903 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 904 /* Use regular, unsafe API. */ 905 typedef int _Xatimeparams; /* dummy */ 906 # define _XAsctime(t,p) asctime((t)) 907 typedef int _Xctimeparams; /* dummy */ 908 # define _XCtime(t,p) ctime((t)) 909 typedef int _Xgtimeparams; /* dummy */ 910 # define _XGmtime(t,p) gmtime((t)) 911 typedef int _Xltimeparams; /* dummy */ 912 # define _XLocaltime(t,p) localtime((t)) 913 914 #elif !defined(XOS_USE_MTSAFE_TIMEAPI) || defined(XNO_MTSAFE_TIMEAPI) 915 /* Systems with thread support but no _r API. */ 916 typedef struct { 917 # ifdef TIMELEN 918 char buf[TIMELEN]; 919 # else 920 char buf[26]; 921 # endif 922 char *result; 923 } _Xctimeparams, _Xatimeparams; 924 typedef struct { 925 struct tm buf; 926 struct tm *result; 927 } _Xgtimeparams, _Xltimeparams; 928 # define _XAsctime(t,p) \ 929 ( (_Xos_processLock), \ 930 (((p).result = asctime((t))) ? \ 931 (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 932 0), \ 933 (_Xos_processUnlock), \ 934 (p).result ) 935 # define _XCtime(t,p) \ 936 ( (_Xos_processLock), \ 937 (((p).result = ctime((t))) ? \ 938 (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 939 0), \ 940 (_Xos_processUnlock), \ 941 (p).result ) 942 # define _XGmtime(t,p) \ 943 ( (_Xos_processLock), \ 944 (((p).result = gmtime(t)) ? \ 945 (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 946 0), \ 947 (_Xos_processUnlock), \ 948 (p).result ) 949 # define _XLocaltime(t,p) \ 950 ( (_Xos_processLock), \ 951 (((p).result = localtime(t)) ? \ 952 (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \ 953 0), \ 954 (_Xos_processUnlock), \ 955 (p).result ) 956 957 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(__osf__) || defined(hpV4)) 958 /* Returns (int)0 on success. OSF/1 v3.2, HP/UX 10 959 * 960 * extern int asctime_r(const struct tm *timeptr, char *buffer, int buflen); 961 * extern int ctime_r(const time_t *timer, char *buffer, int buflen); 962 * extern int gmtime_r(const time_t *timer, struct tm *result); 963 * extern int localtime_r(const time_t *timer, struct tm *result); 964 */ 965 # ifdef TIMELEN 966 typedef char _Xatimeparams[TIMELEN]; 967 typedef char _Xctimeparams[TIMELEN]; 968 # else 969 typedef char _Xatimeparams[26]; 970 typedef char _Xctimeparams[26]; 971 # endif 972 typedef struct tm _Xgtimeparams; 973 typedef struct tm _Xltimeparams; 974 # define _XAsctime(t,p) (asctime_r((t),(p),sizeof((p))) ? NULL : (p)) 975 # define _XCtime(t,p) (ctime_r((t),(p),sizeof((p))) ? NULL : (p)) 976 # define _XGmtime(t,p) (gmtime_r((t),&(p)) ? NULL : &(p)) 977 # define _XLocaltime(t,p) (localtime_r((t),&(p)) ? NULL : &(p)) 978 979 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(sun) 980 /* Returns NULL on failure. Solaris 2.5 981 * 982 * extern char *asctime_r(const struct tm *tm,char *buf, int buflen); 983 * extern char *ctime_r(const time_t *clock, char *buf, int buflen); 984 * extern struct tm *gmtime_r(const time_t *clock, struct tm *res); 985 * extern struct tm *localtime_r(const time_t *clock, struct tm *res); 986 */ 987 # ifdef TIMELEN 988 typedef char _Xatimeparams[TIMELEN]; 989 typedef char _Xctimeparams[TIMELEN]; 990 # else 991 typedef char _Xatimeparams[26]; 992 typedef char _Xctimeparams[26]; 993 # endif 994 typedef struct tm _Xgtimeparams; 995 typedef struct tm _Xltimeparams; 996 # define _XAsctime(t,p) asctime_r((t),(p),sizeof((p))) 997 # define _XCtime(t,p) ctime_r((t),(p),sizeof((p))) 998 # define _XGmtime(t,p) gmtime_r((t),&(p)) 999 # define _XLocaltime(t,p) localtime_r((t),&(p)) 1000 1001 #else /* defined(_POSIX_THREAD_SAFE_FUNCTIONS) */ 1002 /* POSIX final API. OSF/1 v4.0, AIX, etc. 1003 * 1004 * extern char *asctime_r(const struct tm *timeptr, char *buffer); 1005 * extern char *ctime_r(const time_t *timer, char *buffer); 1006 * extern struct tm *gmtime_r(const time_t *timer, struct tm *result); 1007 * extern struct tm *localtime_r(const time_t *timer, struct tm *result); 1008 */ 1009 # if defined(__osf__) 1010 /* OSF/1 V4.0 <time.h> doesn't declare the _P routines, breaking under C++. */ 1011 extern char *_Pasctime_r(const struct tm *, char *); 1012 extern char *_Pctime_r(const time_t *, char *); 1013 extern struct tm *_Plocaltime_r(const time_t *, struct tm *); 1014 # endif 1015 # ifdef TIMELEN 1016 typedef char _Xatimeparams[TIMELEN]; 1017 typedef char _Xctimeparams[TIMELEN]; 1018 # else 1019 typedef char _Xatimeparams[26]; 1020 typedef char _Xctimeparams[26]; 1021 # endif 1022 typedef struct tm _Xgtimeparams; 1023 typedef struct tm _Xltimeparams; 1024 # define _XAsctime(t,p) asctime_r((t),(p)) 1025 # define _XCtime(t,p) ctime_r((t),(p)) 1026 # define _XGmtime(t,p) gmtime_r((t),&(p)) 1027 # define _XLocaltime(t,p) localtime_r((t),&(p)) 1028 #endif /* X_INCLUDE_TIME_H */ 1029 1030 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H) 1031 # define _XOS_INCLUDED_TIME_H 1032 #endif 1033 1034 1035 /***** <grp.h> wrappers *****/ 1036 1037 /* 1038 * Effective prototypes for <grp.h> wrappers: 1039 * 1040 * NOTE: On systems lacking appropriate _r functions Getgrgid() and 1041 * Getgrnam() do NOT copy the list of group members! 1042 * 1043 * Remember that fgetgrent(), setgrent(), getgrent(), and endgrent() 1044 * are not included in POSIX. 1045 * 1046 * #define X_INCLUDE_GRP_H 1047 * #define XOS_USE_..._LOCKING 1048 * #include <X11/Xos_r.h> 1049 * 1050 * typedef ... _Xgetgrparams; 1051 * 1052 * struct group *_XGetgrgid(gid_t, _Xgetgrparams); 1053 * struct group *_XGetgrnam(const char *, _Xgetgrparams); 1054 */ 1055 1056 #if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H) 1057 # include <grp.h> 1058 # if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_GRPAPI) 1059 # define XOS_USE_MTSAFE_GRPAPI 1 1060 # endif 1061 #endif 1062 1063 #if !defined(X_INCLUDE_GRP_H) || defined(_XOS_INCLUDED_GRP_H) 1064 /* Do nothing. */ 1065 1066 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API) 1067 /* Use regular, unsafe API. */ 1068 typedef int _Xgetgrparams; /* dummy */ 1069 #define _XGetgrgid(g,p) getgrgid((g)) 1070 #define _XGetgrnam(n,p) getgrnam((n)) 1071 1072 #elif !defined(XOS_USE_MTSAFE_GRPAPI) || defined(XNO_MTSAFE_GRPAPI) 1073 /* Systems with thread support but no _r API. UnixWare 2.0. */ 1074 typedef struct { 1075 struct group grp; 1076 char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 1077 struct group *pgrp; 1078 size_t len; 1079 } _Xgetgrparams; 1080 #ifdef SVR4 1081 /* Copy the gr_passwd field too. */ 1082 # define _Xgrp_copyGroup(p) \ 1083 ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \ 1084 ((p).grp.gr_name = (p).buf), \ 1085 ((p).len = strlen((p).pgrp->gr_name)), \ 1086 strcpy((p).grp.gr_name, (p).pgrp->gr_name), \ 1087 ((p).grp.gr_passwd = (p).grp.gr_name + (p).len + 1), \ 1088 ((p).pgrp = &(p).grp), \ 1089 0 ) 1090 #else 1091 # define _Xgrp_copyGroup(p) \ 1092 ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \ 1093 ((p).grp.gr_name = (p).buf), \ 1094 strcpy((p).grp.gr_name, (p).pgrp->gr_name), \ 1095 ((p).pgrp = &(p).grp), \ 1096 0 ) 1097 #endif 1098 #define _XGetgrgid(g,p) \ 1099 ( (_Xos_processLock), \ 1100 (((p).pgrp = getgrgid((g))) ? _Xgrp_copyGroup(p) : 0), \ 1101 (_Xos_processUnlock), \ 1102 (p).pgrp ) 1103 #define _XGetgrnam(n,p) \ 1104 ( (_Xos_processLock), \ 1105 (((p).pgrp = getgrnam((n))) ? _Xgrp_copyGroup(p) : 0), \ 1106 (_Xos_processUnlock), \ 1107 (p).pgrp ) 1108 1109 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(sun) || defined(__osf__)) 1110 /* Non-POSIX API. Solaris, DEC v3.2. 1111 * 1112 * extern struct group *getgrgid_r(gid_t, struct group *, char *, int); 1113 * extern struct group *getgrnam_r(const char *, struct group *, char *, int); 1114 */ 1115 typedef struct { 1116 struct group grp; 1117 char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 1118 } _Xgetgrparams; 1119 #define _XGetgrgid(g,p) getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) 1120 #define _XGetgrnam(n,p) getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) 1121 1122 #elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) 1123 /* Non-POSIX API. HP/UX 10, AIX 4. 1124 * 1125 * extern int getgrgid_r(gid_t, struct group *, char *, int); 1126 * extern int getgrnam_r(const char *, struct group *, char *, int); 1127 */ 1128 typedef struct { 1129 struct group grp; 1130 char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 1131 } _Xgetgrparams; 1132 #define _XGetgrgid(g,p) \ 1133 ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp)) 1134 #define _XGetgrnam(n,p) \ 1135 ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp)) 1136 1137 #else 1138 /* POSIX final API. DEC v4.0, IRIX 6.2. 1139 * 1140 * int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); 1141 * int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); 1142 */ 1143 # if defined(__osf__) 1144 /* OSF/1 V4.0 <grp.h> doesn't declare the _P routines, breaking under C++. */ 1145 extern int _Pgetgrgid_r(gid_t, struct group *, char *, size_t, struct group **); 1146 extern int _Pgetgrnam_r(const char *, struct group *, char *, size_t, struct group **); 1147 # endif 1148 typedef struct { 1149 struct group grp; 1150 char buf[X_LINE_MAX]; /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */ 1151 struct group *result; 1152 } _Xgetgrparams; 1153 1154 #define _XGetgrgid(g,p) \ 1155 ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \ 1156 NULL : (p).result)) 1157 #define _XGetgrnam(n,p) \ 1158 ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \ 1159 NULL : (p).result)) 1160 #endif 1161 1162 #if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H) 1163 # define _XOS_INCLUDED_GRP_H 1164 #endif 1165 1166 1167 #ifdef __cplusplus 1168 } /* Close scope of 'extern "C"' declaration which encloses file. */ 1169 #endif 1170