Back to index

lightning-sunbird  0.9+nobinonly
libc_r.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* libc_r.h  --  macros, defines, etc. to make using reentrant libc calls */
00039 /*               a bit easier.  This was initially done for AIX pthreads, */
00040 /*               but should be usable for anyone...                       */
00041 
00042 /* Most of these use locally defined space instead of static library space. */
00043 /* Because of this, we use the _INIT_R to declare/allocate space (stack),   */
00044 /* and the plain routines to actually do it..._WARNING_: avoid allocating   */
00045 /* memory wherever possible.  Memory allocation is fairly expensive, at     */
00046 /* least on AIX...use arrays instead (which allocate from the stack.)       */
00047 /* I know the names are a bit strange, but I wanted to be fairly certain    */
00048 /* that we didn't have any namespace corruption...in general, the inits are */
00049 /* R_<name>_INIT_R(), and the actual calls are R_<name>_R().                */
00050 
00051 #ifndef _LIBC_R_H
00052 #define _LIBC_R_H
00053 
00054 /************/
00055 /*  strtok  */
00056 /************/
00057 #define R_STRTOK_INIT_R() \
00058     char *r_strtok_r=NULL
00059 
00060 #define R_STRTOK_R(return,source,delim) \     
00061     return=strtok_r(source,delim,&r_strtok_r)
00062 
00063 #define R_STRTOK_NORET_R(source,delim) \
00064     strtok_r(source,delim,&r_strtok_r)
00065 
00066 /**************/
00067 /*  strerror  */
00068 /**************/
00069 #define R_MAX_STRERROR_LEN_R 8192     /* Straight from limits.h */
00070 
00071 #define R_STRERROR_INIT_R() \
00072     char r_strerror_r[R_MAX_STRERROR_LEN_R]
00073 
00074 #define R_STRERROR_R(val) \
00075     strerror_r(val,r_strerror_r,R_MAX_STRERROR_LEN_R)
00076 
00077 /*****************/
00078 /*  time things  */
00079 /*****************/
00080 #define R_ASCTIME_INIT_R() \
00081     char r_asctime_r[26]
00082 
00083 #define R_ASCTIME_R(val) \
00084     asctime_r(val,r_asctime_r)
00085 
00086 #define R_CTIME_INIT_R() \
00087     char r_ctime_r[26]
00088 
00089 #define R_CTIME_R(val) \
00090     ctime_r(val,r_ctime_r)
00091 
00092 #define R_GMTIME_INIT_R() \
00093     struct tm r_gmtime_r
00094 
00095 #define R_GMTIME_R(time) \
00096     gmtime_r(time,&r_gmtime_r)
00097 
00098 #define R_LOCALTIME_INIT_R() \
00099    struct tm r_localtime_r
00100 
00101 #define R_LOCALTIME_R(val) \
00102    localtime_r(val,&r_localtime_r)
00103     
00104 /***********/
00105 /*  crypt  */
00106 /***********/
00107 #include <crypt.h>
00108 #define R_CRYPT_INIT_R() \
00109     CRYPTD r_cryptd_r; \
00110     bzero(&r_cryptd_r,sizeof(CRYPTD)) 
00111 
00112 #define R_CRYPT_R(pass,salt) \
00113     crypt_r(pass,salt,&r_cryptd_r)
00114 
00115 /**************/
00116 /*  pw stuff  */
00117 /**************/
00118 #define R_MAX_PW_LEN_R 1024
00119 /* The following must be after the last declaration, but */
00120 /* before the first bit of code...                       */
00121 #define R_GETPWNAM_INIT_R(pw_ptr) \
00122     struct passwd r_getpwnam_pw_r; \
00123     char r_getpwnam_line_r[R_MAX_PW_LEN_R]; \
00124     pw_ptr = &r_getpwnam_pw_r
00125 
00126 #define R_GETPWNAM_R(name) \
00127     getpwnam_r(name,&r_getpwnam_pw_r,r_getpwnam_line_r,R_MAX_PW_LEN_R)
00128 
00129 /*******************/
00130 /*  gethost stuff  */
00131 /*******************/
00132 #define R_GETHOSTBYADDR_INIT_R() \
00133     struct hostent r_gethostbyaddr_r; \
00134     struct hostent_data r_gethostbyaddr_data_r
00135 
00136 #define R_GETHOSTBYADDR_R(addr,len,type,xptr_ent) \
00137     bzero(&r_gethostbyaddr_r,sizeof(struct hostent)); \
00138     bzero(&r_gethostbyaddr_data_r,sizeof(struct hostent_data)); \
00139     xptr_ent = &r_gethostbyaddr_r; \
00140     if (gethostbyaddr_r(addr,len,type, \
00141        &r_gethostbyaddr_r,&r_gethostbyaddr_data_r) == -1) { \
00142            xptr_ent = NULL; \
00143     }
00144 
00145 #define R_GETHOSTBYNAME_INIT_R() \
00146     struct hostent r_gethostbyname_r; \
00147     struct hostent_data r_gethostbyname_data_r
00148 
00149 #define R_GETHOSTBYNAME_R(name,xptr_ent) \
00150     bzero(&r_gethostbyname_r,sizeof(struct hostent)); \
00151     bzero(&r_gethostbyname_data_r,sizeof(struct hostent_data)); \
00152     xptr_ent = &r_gethostbyname_r; \
00153     if (gethostbyname_r(name, \
00154        &r_gethostbyname_r,&r_gethostbyname_data_r) == -1) { \
00155           xptr_ent = NULL; \
00156     }
00157 
00158 #endif /* _LIBC_R_H */