1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 * secport.h - portability interfaces for security libraries
40 * $Id: secport.h,v 1.15 2008/02/14 18:41:38 wtc%google.com Exp $
46 #include "utilrename.h"
49 * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
62 #if defined(_WIN32) || defined(WIN32)
85 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
89 #if defined(_WIN32_WCE)
92 #elif defined( XP_MAC )
94 #include <time.h> /* for time_t below */
96 #include <sys/types.h>
101 #if defined(_WIN32_WCE)
102 #include <stdlib.h> /* WinCE puts some stddef symbols here. */
108 #include "prlog.h" /* for PR_ASSERT */
113 * HACK for NSS 2.8 to allow Admin to compile without source changes.
115 #ifndef SEC_BEGIN_PROTOS
116 #include "seccomon.h"
121 extern void *PORT_Alloc(size_t len
);
122 extern void *PORT_Realloc(void *old
, size_t len
);
123 extern void *PORT_AllocBlock(size_t len
);
124 extern void *PORT_ReallocBlock(void *old
, size_t len
);
125 extern void PORT_FreeBlock(void *ptr
);
126 extern void *PORT_ZAlloc(size_t len
);
127 extern void PORT_Free(void *ptr
);
128 extern void PORT_ZFree(void *ptr
, size_t len
);
129 extern char *PORT_Strdup(const char *s
);
130 extern time_t PORT_Time(void);
131 extern void PORT_SetError(int value
);
132 extern int PORT_GetError(void);
134 extern PLArenaPool
*PORT_NewArena(unsigned long chunksize
);
135 extern void *PORT_ArenaAlloc(PLArenaPool
*arena
, size_t size
);
136 extern void *PORT_ArenaZAlloc(PLArenaPool
*arena
, size_t size
);
137 extern void PORT_FreeArena(PLArenaPool
*arena
, PRBool zero
);
138 extern void *PORT_ArenaGrow(PLArenaPool
*arena
, void *ptr
,
139 size_t oldsize
, size_t newsize
);
140 extern void *PORT_ArenaMark(PLArenaPool
*arena
);
141 extern void PORT_ArenaRelease(PLArenaPool
*arena
, void *mark
);
142 extern void PORT_ArenaZRelease(PLArenaPool
*arena
, void *mark
);
143 extern void PORT_ArenaUnmark(PLArenaPool
*arena
, void *mark
);
144 extern char *PORT_ArenaStrdup(PLArenaPool
*arena
, const char *str
);
148 #define PORT_Assert PR_ASSERT
149 #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type))
150 #define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
151 #define PORT_ArenaNew(poolp, type) \
152 (type*) PORT_ArenaAlloc(poolp, sizeof(type))
153 #define PORT_ArenaZNew(poolp, type) \
154 (type*) PORT_ArenaZAlloc(poolp, sizeof(type))
155 #define PORT_NewArray(type, num) \
156 (type*) PORT_Alloc (sizeof(type)*(num))
157 #define PORT_ZNewArray(type, num) \
158 (type*) PORT_ZAlloc (sizeof(type)*(num))
159 #define PORT_ArenaNewArray(poolp, type, num) \
160 (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num))
161 #define PORT_ArenaZNewArray(poolp, type, num) \
162 (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num))
164 /* Please, keep these defines sorted alphabetically. Thanks! */
166 #define PORT_Atoi atoi
168 #define PORT_Memcmp memcmp
169 #define PORT_Memcpy memcpy
171 #define PORT_Memmove memmove
173 #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n))
175 #define PORT_Memset memset
177 #define PORT_Strcasecmp PL_strcasecmp
178 #define PORT_Strcat strcat
179 #define PORT_Strchr strchr
180 #define PORT_Strrchr strrchr
181 #define PORT_Strcmp strcmp
182 #define PORT_Strcpy strcpy
183 #define PORT_Strlen(s) strlen(s)
184 #define PORT_Strncasecmp PL_strncasecmp
185 #define PORT_Strncat strncat
186 #define PORT_Strncmp strncmp
187 #define PORT_Strncpy strncpy
188 #define PORT_Strpbrk strpbrk
189 #define PORT_Strstr strstr
190 #define PORT_Strtok strtok
192 #define PORT_Tolower tolower
194 typedef PRBool (PR_CALLBACK
* PORTCharConversionWSwapFunc
) (PRBool toUnicode
,
195 unsigned char *inBuf
, unsigned int inBufLen
,
196 unsigned char *outBuf
, unsigned int maxOutBufLen
,
197 unsigned int *outBufLen
, PRBool swapBytes
);
199 typedef PRBool (PR_CALLBACK
* PORTCharConversionFunc
) (PRBool toUnicode
,
200 unsigned char *inBuf
, unsigned int inBufLen
,
201 unsigned char *outBuf
, unsigned int maxOutBufLen
,
202 unsigned int *outBufLen
);
206 void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
207 void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc
);
208 PRBool
PORT_UCS4_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
209 unsigned int inBufLen
, unsigned char *outBuf
,
210 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
211 PRBool
PORT_UCS2_ASCIIConversion(PRBool toUnicode
, unsigned char *inBuf
,
212 unsigned int inBufLen
, unsigned char *outBuf
,
213 unsigned int maxOutBufLen
, unsigned int *outBufLen
,
215 void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
216 PRBool
PORT_UCS2_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
217 unsigned int inBufLen
, unsigned char *outBuf
,
218 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
220 /* One-way conversion from ISO-8859-1 to UTF-8 */
221 PRBool
PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf
,
222 unsigned int inBufLen
, unsigned char *outBuf
,
223 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
226 sec_port_ucs4_utf8_conversion_function
229 unsigned char *inBuf
,
230 unsigned int inBufLen
,
231 unsigned char *outBuf
,
232 unsigned int maxOutBufLen
,
233 unsigned int *outBufLen
237 sec_port_ucs2_utf8_conversion_function
240 unsigned char *inBuf
,
241 unsigned int inBufLen
,
242 unsigned char *outBuf
,
243 unsigned int maxOutBufLen
,
244 unsigned int *outBufLen
247 /* One-way conversion from ISO-8859-1 to UTF-8 */
249 sec_port_iso88591_utf8_conversion_function
251 const unsigned char *inBuf
,
252 unsigned int inBufLen
,
253 unsigned char *outBuf
,
254 unsigned int maxOutBufLen
,
255 unsigned int *outBufLen
258 extern int NSS_PutEnv(const char * envVarName
, const char * envValue
);
262 #endif /* _SECPORT_H_ */