Backed out changeset bcc246bfd4aa (bug 1862763) for causing build bustages CLOSED...
[gecko.git] / nsprpub / config / libc_r.h
blob2af8f2efa7ddcc51c1486ee04a61e2909e0b72d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* libc_r.h -- macros, defines, etc. to make using reentrant libc calls */
7 /* a bit easier. This was initially done for AIX pthreads, */
8 /* but should be usable for anyone... */
10 /* Most of these use locally defined space instead of static library space. */
11 /* Because of this, we use the _INIT_R to declare/allocate space (stack), */
12 /* and the plain routines to actually do it..._WARNING_: avoid allocating */
13 /* memory wherever possible. Memory allocation is fairly expensive, at */
14 /* least on AIX...use arrays instead (which allocate from the stack.) */
15 /* I know the names are a bit strange, but I wanted to be fairly certain */
16 /* that we didn't have any namespace corruption...in general, the inits are */
17 /* R_<name>_INIT_R(), and the actual calls are R_<name>_R(). */
19 #ifndef _LIBC_R_H
20 #define _LIBC_R_H
22 /************/
23 /* strtok */
24 /************/
25 #define R_STRTOK_INIT_R() \
26 char *r_strtok_r=NULL
28 #define R_STRTOK_R(return,source,delim) \
29 return=strtok_r(source,delim,&r_strtok_r)
31 #define R_STRTOK_NORET_R(source,delim) \
32 strtok_r(source,delim,&r_strtok_r)
34 /**************/
35 /* strerror */
36 /**************/
37 #define R_MAX_STRERROR_LEN_R 8192 /* Straight from limits.h */
39 #define R_STRERROR_INIT_R() \
40 char r_strerror_r[R_MAX_STRERROR_LEN_R]
42 #define R_STRERROR_R(val) \
43 strerror_r(val,r_strerror_r,R_MAX_STRERROR_LEN_R)
45 /*****************/
46 /* time things */
47 /*****************/
48 #define R_ASCTIME_INIT_R() \
49 char r_asctime_r[26]
51 #define R_ASCTIME_R(val) \
52 asctime_r(val,r_asctime_r)
54 #define R_CTIME_INIT_R() \
55 char r_ctime_r[26]
57 #define R_CTIME_R(val) \
58 ctime_r(val,r_ctime_r)
60 #define R_GMTIME_INIT_R() \
61 struct tm r_gmtime_r
63 #define R_GMTIME_R(time) \
64 gmtime_r(time,&r_gmtime_r)
66 #define R_LOCALTIME_INIT_R() \
67 struct tm r_localtime_r
69 #define R_LOCALTIME_R(val) \
70 localtime_r(val,&r_localtime_r)
72 /***********/
73 /* crypt */
74 /***********/
75 #include <crypt.h>
76 #define R_CRYPT_INIT_R() \
77 CRYPTD r_cryptd_r; \
78 bzero(&r_cryptd_r,sizeof(CRYPTD))
80 #define R_CRYPT_R(pass,salt) \
81 crypt_r(pass,salt,&r_cryptd_r)
83 /**************/
84 /* pw stuff */
85 /**************/
86 #define R_MAX_PW_LEN_R 1024
87 /* The following must be after the last declaration, but */
88 /* before the first bit of code... */
89 #define R_GETPWNAM_INIT_R(pw_ptr) \
90 struct passwd r_getpwnam_pw_r; \
91 char r_getpwnam_line_r[R_MAX_PW_LEN_R]; \
92 pw_ptr = &r_getpwnam_pw_r
94 #define R_GETPWNAM_R(name) \
95 getpwnam_r(name,&r_getpwnam_pw_r,r_getpwnam_line_r,R_MAX_PW_LEN_R)
97 /*******************/
98 /* gethost stuff */
99 /*******************/
100 #define R_GETHOSTBYADDR_INIT_R() \
101 struct hostent r_gethostbyaddr_r; \
102 struct hostent_data r_gethostbyaddr_data_r
104 #define R_GETHOSTBYADDR_R(addr,len,type,xptr_ent) \
105 bzero(&r_gethostbyaddr_r,sizeof(struct hostent)); \
106 bzero(&r_gethostbyaddr_data_r,sizeof(struct hostent_data)); \
107 xptr_ent = &r_gethostbyaddr_r; \
108 if (gethostbyaddr_r(addr,len,type, \
109 &r_gethostbyaddr_r,&r_gethostbyaddr_data_r) == -1) { \
110 xptr_ent = NULL; \
113 #define R_GETHOSTBYNAME_INIT_R() \
114 struct hostent r_gethostbyname_r; \
115 struct hostent_data r_gethostbyname_data_r
117 #define R_GETHOSTBYNAME_R(name,xptr_ent) \
118 bzero(&r_gethostbyname_r,sizeof(struct hostent)); \
119 bzero(&r_gethostbyname_data_r,sizeof(struct hostent_data)); \
120 xptr_ent = &r_gethostbyname_r; \
121 if (gethostbyname_r(name, \
122 &r_gethostbyname_r,&r_gethostbyname_data_r) == -1) { \
123 xptr_ent = NULL; \
126 #endif /* _LIBC_R_H */