nsprpub/config/libc_r.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial