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.13 2006/08/15 23:56:01 wtchang%redhat.com Exp $
47 * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
60 #if defined(_WIN32) || defined(WIN32)
83 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
87 #if defined(_WIN32_WCE)
90 #elif defined( XP_MAC )
92 #include <time.h> /* for time_t below */
94 #include <sys/types.h>
99 #if defined(_WIN32_WCE)
100 #include <stdlib.h> /* WinCE puts some stddef symbols here. */
106 #include "prlog.h" /* for PR_ASSERT */
111 * HACK for NSS 2.8 to allow Admin to compile without source changes.
113 #ifndef SEC_BEGIN_PROTOS
114 #include "seccomon.h"
119 extern void *PORT_Alloc(size_t len
);
120 extern void *PORT_Realloc(void *old
, size_t len
);
121 extern void *PORT_AllocBlock(size_t len
);
122 extern void *PORT_ReallocBlock(void *old
, size_t len
);
123 extern void PORT_FreeBlock(void *ptr
);
124 extern void *PORT_ZAlloc(size_t len
);
125 extern void PORT_Free(void *ptr
);
126 extern void PORT_ZFree(void *ptr
, size_t len
);
127 extern char *PORT_Strdup(const char *s
);
128 extern time_t PORT_Time(void);
129 extern void PORT_SetError(int value
);
130 extern int PORT_GetError(void);
132 extern PLArenaPool
*PORT_NewArena(unsigned long chunksize
);
133 extern void *PORT_ArenaAlloc(PLArenaPool
*arena
, size_t size
);
134 extern void *PORT_ArenaZAlloc(PLArenaPool
*arena
, size_t size
);
135 extern void PORT_FreeArena(PLArenaPool
*arena
, PRBool zero
);
136 extern void *PORT_ArenaGrow(PLArenaPool
*arena
, void *ptr
,
137 size_t oldsize
, size_t newsize
);
138 extern void *PORT_ArenaMark(PLArenaPool
*arena
);
139 extern void PORT_ArenaRelease(PLArenaPool
*arena
, void *mark
);
140 extern void PORT_ArenaZRelease(PLArenaPool
*arena
, void *mark
);
141 extern void PORT_ArenaUnmark(PLArenaPool
*arena
, void *mark
);
142 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
);
208 void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
209 void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc
);
210 PRBool
PORT_UCS4_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
211 unsigned int inBufLen
, unsigned char *outBuf
,
212 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
213 PRBool
PORT_UCS2_ASCIIConversion(PRBool toUnicode
, unsigned char *inBuf
,
214 unsigned int inBufLen
, unsigned char *outBuf
,
215 unsigned int maxOutBufLen
, unsigned int *outBufLen
,
217 void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc
);
218 PRBool
PORT_UCS2_UTF8Conversion(PRBool toUnicode
, unsigned char *inBuf
,
219 unsigned int inBufLen
, unsigned char *outBuf
,
220 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
222 /* One-way conversion from ISO-8859-1 to UTF-8 */
223 PRBool
PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf
,
224 unsigned int inBufLen
, unsigned char *outBuf
,
225 unsigned int maxOutBufLen
, unsigned int *outBufLen
);
228 sec_port_ucs4_utf8_conversion_function
231 unsigned char *inBuf
,
232 unsigned int inBufLen
,
233 unsigned char *outBuf
,
234 unsigned int maxOutBufLen
,
235 unsigned int *outBufLen
239 sec_port_ucs2_utf8_conversion_function
242 unsigned char *inBuf
,
243 unsigned int inBufLen
,
244 unsigned char *outBuf
,
245 unsigned int maxOutBufLen
,
246 unsigned int *outBufLen
249 /* One-way conversion from ISO-8859-1 to UTF-8 */
251 sec_port_iso88591_utf8_conversion_function
253 const unsigned char *inBuf
,
254 unsigned int inBufLen
,
255 unsigned char *outBuf
,
256 unsigned int maxOutBufLen
,
257 unsigned int *outBufLen
260 extern int NSS_PutEnv(const char * envVarName
, const char * envValue
);
264 #endif /* _SECPORT_H_ */