nsprpub/config/libc_r.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/config/libc_r.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* libc_r.h  --  macros, defines, etc. to make using reentrant libc calls */
    1.10 +/*               a bit easier.  This was initially done for AIX pthreads, */
    1.11 +/*               but should be usable for anyone...                       */
    1.12 +
    1.13 +/* Most of these use locally defined space instead of static library space. */
    1.14 +/* Because of this, we use the _INIT_R to declare/allocate space (stack),   */
    1.15 +/* and the plain routines to actually do it..._WARNING_: avoid allocating   */
    1.16 +/* memory wherever possible.  Memory allocation is fairly expensive, at     */
    1.17 +/* least on AIX...use arrays instead (which allocate from the stack.)       */
    1.18 +/* I know the names are a bit strange, but I wanted to be fairly certain    */
    1.19 +/* that we didn't have any namespace corruption...in general, the inits are */
    1.20 +/* R_<name>_INIT_R(), and the actual calls are R_<name>_R().                */
    1.21 +
    1.22 +#ifndef _LIBC_R_H
    1.23 +#define _LIBC_R_H
    1.24 +
    1.25 +/************/
    1.26 +/*  strtok  */
    1.27 +/************/
    1.28 +#define R_STRTOK_INIT_R() \
    1.29 +    char *r_strtok_r=NULL
    1.30 +
    1.31 +#define R_STRTOK_R(return,source,delim) \     
    1.32 +    return=strtok_r(source,delim,&r_strtok_r)
    1.33 +
    1.34 +#define R_STRTOK_NORET_R(source,delim) \
    1.35 +    strtok_r(source,delim,&r_strtok_r)
    1.36 +
    1.37 +/**************/
    1.38 +/*  strerror  */
    1.39 +/**************/
    1.40 +#define R_MAX_STRERROR_LEN_R 8192     /* Straight from limits.h */
    1.41 +
    1.42 +#define R_STRERROR_INIT_R() \
    1.43 +    char r_strerror_r[R_MAX_STRERROR_LEN_R]
    1.44 +
    1.45 +#define R_STRERROR_R(val) \
    1.46 +    strerror_r(val,r_strerror_r,R_MAX_STRERROR_LEN_R)
    1.47 +
    1.48 +/*****************/
    1.49 +/*  time things  */
    1.50 +/*****************/
    1.51 +#define R_ASCTIME_INIT_R() \
    1.52 +    char r_asctime_r[26]
    1.53 +
    1.54 +#define R_ASCTIME_R(val) \
    1.55 +    asctime_r(val,r_asctime_r)
    1.56 +
    1.57 +#define R_CTIME_INIT_R() \
    1.58 +    char r_ctime_r[26]
    1.59 +
    1.60 +#define R_CTIME_R(val) \
    1.61 +    ctime_r(val,r_ctime_r)
    1.62 +
    1.63 +#define R_GMTIME_INIT_R() \
    1.64 +    struct tm r_gmtime_r
    1.65 +
    1.66 +#define R_GMTIME_R(time) \
    1.67 +    gmtime_r(time,&r_gmtime_r)
    1.68 +
    1.69 +#define R_LOCALTIME_INIT_R() \
    1.70 +   struct tm r_localtime_r
    1.71 +
    1.72 +#define R_LOCALTIME_R(val) \
    1.73 +   localtime_r(val,&r_localtime_r)
    1.74 +    
    1.75 +/***********/
    1.76 +/*  crypt  */
    1.77 +/***********/
    1.78 +#include <crypt.h>
    1.79 +#define R_CRYPT_INIT_R() \
    1.80 +    CRYPTD r_cryptd_r; \
    1.81 +    bzero(&r_cryptd_r,sizeof(CRYPTD)) 
    1.82 +
    1.83 +#define R_CRYPT_R(pass,salt) \
    1.84 +    crypt_r(pass,salt,&r_cryptd_r)
    1.85 +
    1.86 +/**************/
    1.87 +/*  pw stuff  */
    1.88 +/**************/
    1.89 +#define R_MAX_PW_LEN_R 1024
    1.90 +/* The following must be after the last declaration, but */
    1.91 +/* before the first bit of code...                       */
    1.92 +#define R_GETPWNAM_INIT_R(pw_ptr) \
    1.93 +    struct passwd r_getpwnam_pw_r; \
    1.94 +    char r_getpwnam_line_r[R_MAX_PW_LEN_R]; \
    1.95 +    pw_ptr = &r_getpwnam_pw_r
    1.96 +
    1.97 +#define R_GETPWNAM_R(name) \
    1.98 +    getpwnam_r(name,&r_getpwnam_pw_r,r_getpwnam_line_r,R_MAX_PW_LEN_R)
    1.99 +
   1.100 +/*******************/
   1.101 +/*  gethost stuff  */
   1.102 +/*******************/
   1.103 +#define R_GETHOSTBYADDR_INIT_R() \
   1.104 +    struct hostent r_gethostbyaddr_r; \
   1.105 +    struct hostent_data r_gethostbyaddr_data_r
   1.106 +
   1.107 +#define R_GETHOSTBYADDR_R(addr,len,type,xptr_ent) \
   1.108 +    bzero(&r_gethostbyaddr_r,sizeof(struct hostent)); \
   1.109 +    bzero(&r_gethostbyaddr_data_r,sizeof(struct hostent_data)); \
   1.110 +    xptr_ent = &r_gethostbyaddr_r; \
   1.111 +    if (gethostbyaddr_r(addr,len,type, \
   1.112 +       &r_gethostbyaddr_r,&r_gethostbyaddr_data_r) == -1) { \
   1.113 +           xptr_ent = NULL; \
   1.114 +    }
   1.115 +
   1.116 +#define R_GETHOSTBYNAME_INIT_R() \
   1.117 +    struct hostent r_gethostbyname_r; \
   1.118 +    struct hostent_data r_gethostbyname_data_r
   1.119 +
   1.120 +#define R_GETHOSTBYNAME_R(name,xptr_ent) \
   1.121 +    bzero(&r_gethostbyname_r,sizeof(struct hostent)); \
   1.122 +    bzero(&r_gethostbyname_data_r,sizeof(struct hostent_data)); \
   1.123 +    xptr_ent = &r_gethostbyname_r; \
   1.124 +    if (gethostbyname_r(name, \
   1.125 +       &r_gethostbyname_r,&r_gethostbyname_data_r) == -1) { \
   1.126 +          xptr_ent = NULL; \
   1.127 +    }
   1.128 +
   1.129 +#endif /* _LIBC_R_H */

mercurial