File indexing completed on 2025-01-18 10:15:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
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
0088
0089 #ifndef WIN32
0090
0091 #ifdef __cplusplus
0092 extern "C" {
0093 #endif
0094
0095 # if defined(XOS_USE_XLIB_LOCKING)
0096 # ifndef XAllocIDs
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
0105 # include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */
0106 extern void (*_XLockMutex_fn)(
0107 # if NeedFunctionPrototypes
0108 LockInfoPtr , char * , int
0109 # endif
0110 );
0111 extern void (*_XUnlockMutex_fn)(
0112 # if NeedFunctionPrototypes
0113 LockInfoPtr , char * , int
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
0127 # include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */
0128 extern void (*_XLockMutex_fn)(
0129 # if NeedFunctionPrototypes
0130 LockInfoPtr
0131 # endif
0132 );
0133 extern void (*_XUnlockMutex_fn)(
0134 # if NeedFunctionPrototypes
0135 LockInfoPtr
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
0185
0186
0187
0188
0189
0190 #if defined(sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0191 # undef _POSIX_THREAD_SAFE_FUNCTIONS
0192 #endif
0193
0194
0195
0196
0197
0198 #if defined(Lynx) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
0199 # undef _POSIX_THREAD_SAFE_FUNCTIONS
0200 #endif
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
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
0227
0228 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0229
0230 # if defined(X_NOT_POSIX) && !defined(i386) && !defined(SYSV)
0231 extern struct passwd *getpwuid(), *getpwnam();
0232 # endif
0233 typedef int _Xgetpwparams;
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
0239 typedef struct {
0240 struct passwd pws;
0241 char pwbuf[1024];
0242 struct passwd* pwp;
0243 size_t len;
0244 } _Xgetpwparams;
0245
0246
0247
0248
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
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
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
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
0345
0346 #else
0347
0348 # if defined(__osf__)
0349
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
0366
0367 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
0368 # define _XOS_INCLUDED_PWD_H
0369 #endif
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
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
0405
0406 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0407
0408 typedef int _Xgethostbynameparams;
0409 typedef int _Xgetservbynameparams;
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
0416
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
0466
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
0520 typedef int _Xgethostbynameparams;
0521 typedef int _Xgetservbynameparams;
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
0526
0527 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H)
0528 # define _XOS_INCLUDED_NETDB_H
0529 #endif
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
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
0563
0564 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0565
0566 typedef int _Xreaddirparams;
0567 # define _XReaddir(d,p) readdir(d)
0568
0569 #elif !defined(XOS_USE_MTSAFE_DIRENTAPI) || defined(XNO_MTSAFE_DIRENTAPI)
0570
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
0607
0608 # if defined(__osf__)
0609
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
0617
0618
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
0632 # define _XReaddir(d,p) \
0633 (readdir_r((d),&((p).dir_entry)) ? NULL : &((p).dir_entry))
0634 # elif defined(SVR4)
0635
0636 # define _XReaddir(d,p) (readdir_r((d), &(p).dir_entry))
0637 # else
0638
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
0649
0650 #if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H)
0651 # define _XOS_INCLUDED_DIRENT_H
0652 #endif
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
0672
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
0680
0681 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0682
0683 typedef int _Xgetloginparams;
0684 typedef int _Xttynameparams;
0685 # define _XGetlogin(p) getlogin()
0686 # define _XTtyname(f) ttyname((f))
0687
0688 #elif !defined(XOS_USE_MTSAFE_UNISTDAPI) || defined(XNO_MTSAFE_UNISTDAPI)
0689
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
0732
0733
0734
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
0763
0764
0765
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
0791
0792 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
0793 # define _XOS_INCLUDED_UNISTD_H
0794 #endif
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811 #if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H)
0812
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
0820
0821 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0822
0823 typedef int _Xstrtokparams;
0824 # define _XStrtok(s1,s2,p) strtok((s1),(s2))
0825
0826 #elif !defined(XOS_USE_MTSAFE_STRINGAPI) || defined(XNO_MTSAFE_STRINGAPI)
0827
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
0837 typedef char * _Xstrtokparams;
0838 # define _XStrtok(s1,s2,p) strtok_r((s1),(s2),&(p))
0839 #endif
0840
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857
0858
0859
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
0871
0872 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
0873
0874 typedef int _Xatimeparams;
0875 # define _XAsctime(t,p) asctime((t))
0876 typedef int _Xctimeparams;
0877 # define _XCtime(t,p) ctime((t))
0878 typedef int _Xgtimeparams;
0879 # define _XGmtime(t,p) gmtime((t))
0880 typedef int _Xltimeparams;
0881 # define _XLocaltime(t,p) localtime((t))
0882
0883 #elif !defined(XOS_USE_MTSAFE_TIMEAPI) || defined(XNO_MTSAFE_TIMEAPI)
0884
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
0928
0929
0930
0931
0932
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
0950
0951
0952
0953
0954
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
0971
0972
0973
0974
0975
0976
0977
0978 # if defined(__osf__)
0979
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
0998
0999 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
1000 # define _XOS_INCLUDED_TIME_H
1001 #endif
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
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
1034
1035 #elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
1036
1037 typedef int _Xgetgrparams;
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
1043 typedef struct {
1044 struct group grp;
1045 char buf[X_LINE_MAX];
1046 struct group *pgrp;
1047 size_t len;
1048 } _Xgetgrparams;
1049 #ifdef SVR4
1050
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
1080
1081
1082
1083
1084 typedef struct {
1085 struct group grp;
1086 char buf[X_LINE_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
1093
1094
1095
1096
1097 typedef struct {
1098 struct group grp;
1099 char buf[X_LINE_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
1108
1109
1110
1111
1112 # if defined(__osf__)
1113
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];
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 }
1138 #endif