2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 * secport.h - portability interfaces for security libraries
37 * This file abstracts out libc functionality that libsec depends on
39 * NOTE - These are not public interfaces
41 * $Id: secport.h,v 1.3 2004/10/22 19:11:36 dmitch Exp $
48 * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
61 #if defined(_WIN32) || defined(WIN32)
84 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
88 #if defined(_WIN32_WCE)
91 #elif defined( XP_MAC )
92 #include <sys/types.h>
93 #include <time.h> /* for time_t below */
95 #include <sys/types.h>
100 #include "NSString.h"
106 #if defined(_WIN32_WCE)
107 #include <stdlib.h> /* WinCE puts some stddef symbols here. */
113 #include "prlog.h" /* for PR_ASSERT */
114 #include "plarenas.h"
118 * HACK for NSS 2.8 to allow Admin to compile without source changes.
120 #ifndef SEC_BEGIN_PROTOS
121 #include "seccomon.h"
126 extern void *PORT_Alloc(size_t len
);
127 extern void *PORT_Realloc(void *old
, size_t len
);
128 extern void *PORT_AllocBlock(size_t len
);
129 extern void *PORT_ReallocBlock(void *old
, size_t len
);
130 extern void PORT_FreeBlock(void *ptr
);
131 extern void *PORT_ZAlloc(size_t len
);
132 extern void PORT_Free(void *ptr
);
133 extern void PORT_ZFree(void *ptr
, size_t len
);
134 extern time_t PORT_Time(void);
135 extern void PORT_SetError(int value
);
136 extern int PORT_GetError(void);
138 extern PLArenaPool
*PORT_NewArena(unsigned long chunksize
);
139 extern void *PORT_ArenaAlloc(PLArenaPool
*arena
, size_t size
);
140 extern void *PORT_ArenaZAlloc(PLArenaPool
*arena
, size_t size
);
141 extern void PORT_FreeArena(PLArenaPool
*arena
, PRBool zero
);
142 extern void *PORT_ArenaGrow(PLArenaPool
*arena
, void *ptr
,
143 size_t oldsize
, size_t newsize
);
144 extern void *PORT_ArenaMark(PLArenaPool
*arena
);
145 extern void PORT_ArenaRelease(PLArenaPool
*arena
, void *mark
);
146 extern void PORT_ArenaUnmark(PLArenaPool
*arena
, void *mark
);
148 extern char *PORT_ArenaStrdup(PLArenaPool
*arena
, const char *str
);
154 #define PORT_Assert PR_ASSERT
155 #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type))
156 #define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
157 #define PORT_ArenaNew(poolp, type) \
158 (type*) PORT_ArenaAlloc(poolp, sizeof(type))
159 #define PORT_ArenaZNew(poolp, type) \
160 (type*) PORT_ArenaZAlloc(poolp, sizeof(type))
161 #define PORT_NewArray(type, num) \
162 (type*) PORT_Alloc (sizeof(type)*(num))
163 #define PORT_ZNewArray(type, num) \
164 (type*) PORT_ZAlloc (sizeof(type)*(num))
165 #define PORT_ArenaNewArray(poolp, type, num) \
166 (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num))
167 #define PORT_ArenaZNewArray(poolp, type, num) \
168 (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num))
170 /* Please, keep these defines sorted alphbetically. Thanks! */
172 #ifdef XP_STRING_FUNCS
174 #define PORT_Atoi XP_ATOI
176 #define PORT_Memcmp XP_MEMCMP
177 #define PORT_Memcpy XP_MEMCPY
178 #define PORT_Memmove XP_MEMMOVE
179 #define PORT_Memset XP_MEMSET
181 #define PORT_Strcasecmp XP_STRCASECMP
182 #define PORT_Strcat XP_STRCAT
183 #define PORT_Strchr XP_STRCHR
184 #define PORT_Strrchr XP_STRRCHR
185 #define PORT_Strcmp XP_STRCMP
186 #define PORT_Strcpy XP_STRCPY
187 #define PORT_Strdup XP_STRDUP
188 #define PORT_Strlen(s) XP_STRLEN(s)
189 #define PORT_Strncasecmp XP_STRNCASECMP
190 #define PORT_Strncat strncat
191 #define PORT_Strncmp XP_STRNCMP
192 #define PORT_Strncpy strncpy
193 #define PORT_Strstr XP_STRSTR
194 #define PORT_Strtok XP_STRTOK_R
196 #define PORT_Tolower XP_TO_LOWER
198 #else /* XP_STRING_FUNCS */
200 #define PORT_Atoi atoi
202 #define PORT_Memcmp memcmp
203 #define PORT_Memcpy memcpy
205 #define PORT_Memmove memmove
207 #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n))
209 #define PORT_Memset memset
211 #define PORT_Strcasecmp PL_strcasecmp
212 #define PORT_Strcat strcat
213 #define PORT_Strchr strchr
214 #define PORT_Strrchr strrchr
215 #define PORT_Strcmp strcmp
216 #define PORT_Strcpy strcpy
217 extern char *PORT_Strdup(const char *s
);
218 #define PORT_Strlen(s) strlen(s)
219 #define PORT_Strncasecmp PL_strncasecmp
220 #define PORT_Strncat strncat
221 #define PORT_Strncmp strncmp
222 #define PORT_Strncpy strncpy
223 #define PORT_Strstr strstr
224 #define PORT_Strtok strtok
226 #define PORT_Tolower tolower
228 #endif /* XP_STRING_FUNCS */
232 typedef PRBool (PR_CALLBACK
* PORTCharConversionWSwapFunc
) (PRBool toUnicode
,
233 unsigned char *inBuf
, unsigned int inBufLen
,
234 unsigned char *outBuf
, unsigned int maxOutBufLen
,
235 unsigned int *outBufLen
, PRBool swapBytes
);
237 typedef PRBool (PR_CALLBACK
* PORTCharConversionFunc
) (PRBool toUnicode
,
238 unsigned char *inBuf
, unsigned int inBufLen
,
239 unsigned char *outBuf
, unsigned int maxOutBufLen
,
240 unsigned int *outBufLen
);
246 void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
247 void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc
);
248 PRBool
PORT_UCS4_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
249 unsigned int inBufLen
, unsigned char *outBuf
,
250 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
251 PRBool
PORT_UCS2_ASCIIConversion(PRBool toUnicode
, unsigned char *inBuf
,
252 unsigned int inBufLen
, unsigned char *outBuf
,
253 unsigned int maxOutBufLen
, unsigned int *outBufLen
,
255 void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
256 PRBool
PORT_UCS2_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
257 unsigned int inBufLen
, unsigned char *outBuf
,
258 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
261 sec_port_ucs4_utf8_conversion_function
264 unsigned char *inBuf
,
265 unsigned int inBufLen
,
266 unsigned char *outBuf
,
267 unsigned int maxOutBufLen
,
268 unsigned int *outBufLen
272 sec_port_ucs2_utf8_conversion_function
275 unsigned char *inBuf
,
276 unsigned int inBufLen
,
277 unsigned char *outBuf
,
278 unsigned int maxOutBufLen
,
279 unsigned int *outBufLen
282 extern int NSS_PutEnv(const char * envVarName
, const char * envValue
);
288 #endif /* __APPLE__ */
290 #endif /* _SECPORT_H_ */