📄 xos_r.h
字号:
/* $XConsortium: Xos_r.h /main/5 1996/12/18 16:29:14 lehors $ *//* Copyright (c) 1996 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* $XFree86: xc/include/Xos_r.h,v 1.3 1997/01/18 07:17:11 dawes Exp $ *//* * Various and sundry Thread-Safe functions used by X11, Motif, and CDE. * * Use this file in MT-safe code where you would have included * <dirent.h> for readdir() * <grp.h> for getgrgid() or getgrnam() * <netdb.h> for gethostbyname(), gethostbyaddr(), or getservbyname() * <pwd.h> for getpwnam() or getpwuid() * <string.h> for strtok() * <time.h> for asctime(), ctime(), localtime(), or gmtime() * <unistd.h> for getlogin() or ttyname() * or their thread-safe analogs. * * If you are on a platform that defines XTHREADS but does not have * MT-safe system API (e.g. UnixWare) you must define _Xos_processLock * and _Xos_processUnlock macros before including this header. If * you are on OSF/1 V3.2 and plan to use readdir(), you must also define * _Xos_isThreadsInitialized. For convenience XOS_USE_XLIB_LOCKING or * XOS_USE_XT_LOCKING may be defined to obtain either Xlib-only or * Xt-based versions of these macros. These macros won't result in * truly thread-safe calls, but they are better than nothing. If you * do not want locking in this situation define XOS_USE_NO_LOCKING. * * NOTE: On systems lacking approriate _r functions Gethostbyname(), * Gethostbyaddr(), and Getservbyname() do NOT copy the host or * protocol lists! * * NOTE: On systems lacking appropriate _r functions Getgrgid() and * Getgrnam() do NOT copy the list of group members! * * This header is nominally intended to simplify porting X11, Motif, and * CDE; it may be useful to other people too. The structure below is * complicated, mostly because P1003.1c (the IEEE POSIX Threads spec) * went through lots of drafts, and some vendors shipped systems based * on draft API that were changed later. Unfortunately POSIX did not * provide a feature-test macro for distinguishing each of the drafts. *//* * This header has several parts. Search for "Effective prototypes" * to locate the beginning of a section. *//* This header can be included multiple times with different defines! */#ifndef _XOS_R_H_# define _XOS_R_H_# include <X11/Xos.h># include <X11/Xfuncs.h># ifndef X_NOT_POSIX# ifdef _POSIX_SOURCE# include <limits.h># else# define _POSIX_SOURCE# include <limits.h># undef _POSIX_SOURCE# endif# endif#endif /* _XOS_R_H */#ifndef WIN32#ifdef __cplusplusextern "C" {#endif# if defined(XOS_USE_XLIB_LOCKING)# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */typedef struct _LockInfoRec *LockInfoPtr;extern LockInfoPtr _Xglobal_lock;# endif# ifndef _Xos_isThreadInitialized# define _Xos_isThreadInitialized (_Xglobal_lock)# endif# if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */extern void (*_XLockMutex_fn)(# if NeedFunctionPrototypes LockInfoPtr /* lock */, char * /* file */, int /* line */# endif);extern void (*_XUnlockMutex_fn)(# if NeedFunctionPrototypes LockInfoPtr /* lock */, char * /* file */, int /* line */# endif);# endif# ifndef _Xos_processLock# define _Xos_processLock \ (_XLockMutex_fn ? (*_XLockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)# endif# ifndef _Xos_processUnlock# define _Xos_processUnlock \ (_XUnlockMutex_fn ? (*_XUnlockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)# endif# else# ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */extern void (*_XLockMutex_fn)(# if NeedFunctionPrototypes LockInfoPtr /* lock */# endif);extern void (*_XUnlockMutex_fn)(# if NeedFunctionPrototypes LockInfoPtr /* lock */# endif);# endif# ifndef _Xos_processLock# define _Xos_processLock \ (_XLockMutex_fn ? ((*_XLockMutex_fn)(_Xglobal_lock), 0) : 0)# endif# ifndef _Xos_processUnlock# define _Xos_processUnlock \ (_XUnlockMutex_fn ? ((*_XUnlockMutex_fn)(_Xglobal_lock), 0) : 0)# endif# endif# elif defined(XOS_USE_XT_LOCKING)extern void (*_XtProcessLock)();# ifndef _XtintrinsicP_h# include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */extern void XtProcessLock(# if NeedFunctionPrototypes void# endif);extern void XtProcessUnlock(# if NeedFunctionPrototypes void# endif);# endif# ifndef _Xos_isThreadInitialized# define _Xos_isThreadInitialized _XtProcessLock# endif# ifndef _Xos_processLock# define _Xos_processLock XtProcessLock()# endif# ifndef _Xos_processUnlock# define _Xos_processUnlock XtProcessUnlock()# endif# elif defined(XOS_USE_NO_LOCKING)# ifndef _Xos_isThreadInitialized# define _Xos_isThreadInitialized 0# endif# ifndef _Xos_processLock# define _Xos_processLock 0# endif# ifndef _Xos_processUnlock# define _Xos_processUnlock 0# endif# endif#endif /* !defined WIN32 *//* * Solaris 2.5 has SVR4 thread-safe API, but defines the POSIX * thread-safe feature test macro. Fix the feature test macro. */#if defined(sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)# undef _POSIX_THREAD_SAFE_FUNCTIONS#endif/***** <pwd.h> wrappers *****//* * Effective prototypes for <pwd.h> wrappers: * * #define X_INCLUDE_PWD_H * #define XOS_USE_..._LOCKING * #include <X11/Xos_r.h> * * typedef ... _Xgetpwparams; * * struct passwd* _XGetpwnam(const char *name, _Xgetpwparams); * struct passwd* _XGetpwuid(uid_t uid, _Xgetpwparams); */#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)# include <pwd.h># if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI)# define XOS_USE_MTSAFE_PWDAPI 1# endif#endif#if !defined(X_INCLUDE_PWD_H) || defined(_XOS_INCLUDED_PWD_H)/* Do nothing */#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)/* Use regular, unsafe API. */# if defined(X_NOT_POSIX) && !defined(i386) && !defined(SYSV)extern struct passwd *getpwuid(), *getpwnam();# endiftypedef int _Xgetpwparams; /* dummy */# define _XGetpwuid(u,p) getpwuid((u))# define _XGetpwnam(u,p) getpwnam((u))#elif !defined(XOS_USE_MTSAFE_PWDAPI) || defined(XNO_MTSAFE_PWDAPI)/* UnixWare 2.0, or other systems with thread support but no _r API. */typedef struct { struct passwd pws; char pwbuf[1024]; struct passwd* pwp; size_t len;} _Xgetpwparams;# define _Xpw_copyPasswd(p) \ (memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)), \ ((p).pws.pw_name = (p).pwbuf), \ ((p).len = strlen((p).pwp->pw_name)), \ strcpy((p).pws.pw_name, (p).pwp->pw_name), \ ((p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_passwd)), \ strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd), \ ((p).pws.pw_age = (p).pws.pw_passwd + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_age)), \ strcpy((p).pws.pw_age, (p).pwp->pw_age), \ ((p).pws.pw_comment = (p).pws.pw_age + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_comment)), \ strcpy((p).pws.pw_comment, (p).pwp->pw_comment), \ ((p).pws.pw_gecos = (p).pws.pw_comment + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_gecos)), \ strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos), \ ((p).pws.pw_dir = (p).pws.pw_comment + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_dir)), \ strcpy((p).pws.pw_dir, (p).pwp->pw_dir), \ ((p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1), \ ((p).len = strlen((p).pwp->pw_shell)), \ strcpy((p).pws.pw_shell, (p).pwp->pw_shell), \ ((p).pwp = &(p).pws), \ 0 )# define _XGetpwuid(u,p) \( (_Xos_processLock), \ (((p).pwp = getpwuid((u))) ? _Xpw_copyPasswd(p) : 0), \ (_Xos_processUnlock), \ (p).pwp )# define _XGetpwnam(u,p) \( (_Xos_processLock), \ (((p).pwp = getpwnam((u))) ? _Xpw_copyPasswd(p) : 0), \ (_Xos_processUnlock), \ (p).pwp )#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS)/* SVR4 threads, AIX 4.2.0 and earlier and OSF/1 3.2 and earlier pthreads */# if defined(Lynx) && !defined(LINE_MAX)# define LINE_MAX 2048 /* what Xthreads.h does */# endiftypedef struct { struct passwd pws; char pwbuf[LINE_MAX];} _Xgetpwparams;# if defined(_POSIX_REENTRANT_FUNCTIONS) || !defined(SVR4) || defined(Lynx)# ifndef Lynx# define _XGetpwuid(u,p) \((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)# define _XGetpwnam(u,p) \((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)# else /* Lynx */# define _XGetpwuid(u,p) \((getpwuid_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)# define _XGetpwnam(u,p) \((getpwnam_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)# endif# else /* SVR4 */# define _XGetpwuid(u,p) \((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)# define _XGetpwnam(u,p) \((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)# endif /* SVR4 */#else /* _POSIX_THREAD_SAFE_FUNCTIONS *//* Digital UNIX 4.0, but not (beta) T4.0-1 */# if defined(__osf__)/* OSF/1 V4.0 <pwd.h> doesn't declare the _P routines, breaking under C++. */extern int _Pgetpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);extern int _Pgetpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);# endiftypedef struct { struct passwd pws; char pwbuf[LINE_MAX]; struct passwd* pwp;} _Xgetpwparams;typedef int _Xgetpwret;# define _XGetpwuid(u,p) \((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \ NULL : (p).pwp)# define _XGetpwnam(u,p) \((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \ NULL : (p).pwp)#endif /* X_INCLUDE_PWD_H */#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)# define _XOS_INCLUDED_PWD_H#endif/***** <netdb.h> wrappers *****//* * Effective prototypes for <netdb.h> wrappers: * * NOTE: On systems lacking the appropriate _r functions Gethostbyname(), * Gethostbyaddr(), and Getservbyname() do NOT copy the host or * protocol lists! * * #define X_INCLUDE_NETDB_H * #define XOS_USE_..._LOCKING * #include <X11/Xos_r.h> * * typedef ... _Xgethostbynameparams; * typedef ... _Xgetservbynameparams; * * struct hostent* _XGethostbyname(const char* name,_Xgethostbynameparams); * struct hostent* _XGethostbyaddr(const char* addr, int len, int type, * _Xgethostbynameparams); * struct servent* _XGetservbyname(const char* name, const char* proto, * _Xgetservbynameparams); */#if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \ && !defined(WIN32)# include <netdb.h># if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI)# define XOS_USE_MTSAFE_NETDBAPI 1# endif#endif#if !defined(X_INCLUDE_NETDB_H) || defined(_XOS_INCLUDED_NETDB_H)/* Do nothing. */#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)/* Use regular, unsafe API. */typedef int _Xgethostbynameparams; /* dummy */typedef int _Xgetservbynameparams; /* dummy */# define _XGethostbyname(h,hp) gethostbyname((h))# define _XGethostbyaddr(a,al,t,hp) gethostbyaddr((a),(al),(t))# define _XGetservbyname(s,p,sp) getservbyname((s),(p))#elif !defined(XOS_USE_MTSAFE_NETDBAPI) || defined(XNO_MTSAFE_NETDBAPI)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -