michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* libc_r.h -- macros, defines, etc. to make using reentrant libc calls */ michael@0: /* a bit easier. This was initially done for AIX pthreads, */ michael@0: /* but should be usable for anyone... */ michael@0: michael@0: /* Most of these use locally defined space instead of static library space. */ michael@0: /* Because of this, we use the _INIT_R to declare/allocate space (stack), */ michael@0: /* and the plain routines to actually do it..._WARNING_: avoid allocating */ michael@0: /* memory wherever possible. Memory allocation is fairly expensive, at */ michael@0: /* least on AIX...use arrays instead (which allocate from the stack.) */ michael@0: /* I know the names are a bit strange, but I wanted to be fairly certain */ michael@0: /* that we didn't have any namespace corruption...in general, the inits are */ michael@0: /* R__INIT_R(), and the actual calls are R__R(). */ michael@0: michael@0: #ifndef _LIBC_R_H michael@0: #define _LIBC_R_H michael@0: michael@0: /************/ michael@0: /* strtok */ michael@0: /************/ michael@0: #define R_STRTOK_INIT_R() \ michael@0: char *r_strtok_r=NULL michael@0: michael@0: #define R_STRTOK_R(return,source,delim) \ michael@0: return=strtok_r(source,delim,&r_strtok_r) michael@0: michael@0: #define R_STRTOK_NORET_R(source,delim) \ michael@0: strtok_r(source,delim,&r_strtok_r) michael@0: michael@0: /**************/ michael@0: /* strerror */ michael@0: /**************/ michael@0: #define R_MAX_STRERROR_LEN_R 8192 /* Straight from limits.h */ michael@0: michael@0: #define R_STRERROR_INIT_R() \ michael@0: char r_strerror_r[R_MAX_STRERROR_LEN_R] michael@0: michael@0: #define R_STRERROR_R(val) \ michael@0: strerror_r(val,r_strerror_r,R_MAX_STRERROR_LEN_R) michael@0: michael@0: /*****************/ michael@0: /* time things */ michael@0: /*****************/ michael@0: #define R_ASCTIME_INIT_R() \ michael@0: char r_asctime_r[26] michael@0: michael@0: #define R_ASCTIME_R(val) \ michael@0: asctime_r(val,r_asctime_r) michael@0: michael@0: #define R_CTIME_INIT_R() \ michael@0: char r_ctime_r[26] michael@0: michael@0: #define R_CTIME_R(val) \ michael@0: ctime_r(val,r_ctime_r) michael@0: michael@0: #define R_GMTIME_INIT_R() \ michael@0: struct tm r_gmtime_r michael@0: michael@0: #define R_GMTIME_R(time) \ michael@0: gmtime_r(time,&r_gmtime_r) michael@0: michael@0: #define R_LOCALTIME_INIT_R() \ michael@0: struct tm r_localtime_r michael@0: michael@0: #define R_LOCALTIME_R(val) \ michael@0: localtime_r(val,&r_localtime_r) michael@0: michael@0: /***********/ michael@0: /* crypt */ michael@0: /***********/ michael@0: #include michael@0: #define R_CRYPT_INIT_R() \ michael@0: CRYPTD r_cryptd_r; \ michael@0: bzero(&r_cryptd_r,sizeof(CRYPTD)) michael@0: michael@0: #define R_CRYPT_R(pass,salt) \ michael@0: crypt_r(pass,salt,&r_cryptd_r) michael@0: michael@0: /**************/ michael@0: /* pw stuff */ michael@0: /**************/ michael@0: #define R_MAX_PW_LEN_R 1024 michael@0: /* The following must be after the last declaration, but */ michael@0: /* before the first bit of code... */ michael@0: #define R_GETPWNAM_INIT_R(pw_ptr) \ michael@0: struct passwd r_getpwnam_pw_r; \ michael@0: char r_getpwnam_line_r[R_MAX_PW_LEN_R]; \ michael@0: pw_ptr = &r_getpwnam_pw_r michael@0: michael@0: #define R_GETPWNAM_R(name) \ michael@0: getpwnam_r(name,&r_getpwnam_pw_r,r_getpwnam_line_r,R_MAX_PW_LEN_R) michael@0: michael@0: /*******************/ michael@0: /* gethost stuff */ michael@0: /*******************/ michael@0: #define R_GETHOSTBYADDR_INIT_R() \ michael@0: struct hostent r_gethostbyaddr_r; \ michael@0: struct hostent_data r_gethostbyaddr_data_r michael@0: michael@0: #define R_GETHOSTBYADDR_R(addr,len,type,xptr_ent) \ michael@0: bzero(&r_gethostbyaddr_r,sizeof(struct hostent)); \ michael@0: bzero(&r_gethostbyaddr_data_r,sizeof(struct hostent_data)); \ michael@0: xptr_ent = &r_gethostbyaddr_r; \ michael@0: if (gethostbyaddr_r(addr,len,type, \ michael@0: &r_gethostbyaddr_r,&r_gethostbyaddr_data_r) == -1) { \ michael@0: xptr_ent = NULL; \ michael@0: } michael@0: michael@0: #define R_GETHOSTBYNAME_INIT_R() \ michael@0: struct hostent r_gethostbyname_r; \ michael@0: struct hostent_data r_gethostbyname_data_r michael@0: michael@0: #define R_GETHOSTBYNAME_R(name,xptr_ent) \ michael@0: bzero(&r_gethostbyname_r,sizeof(struct hostent)); \ michael@0: bzero(&r_gethostbyname_data_r,sizeof(struct hostent_data)); \ michael@0: xptr_ent = &r_gethostbyname_r; \ michael@0: if (gethostbyname_r(name, \ michael@0: &r_gethostbyname_r,&r_gethostbyname_data_r) == -1) { \ michael@0: xptr_ent = NULL; \ michael@0: } michael@0: michael@0: #endif /* _LIBC_R_H */