home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / libc_r.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.5 KB  |  140 lines

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