]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_asn1/security_asn1/prtypes.h
441ca69618e6467c1184aa3ded0286bbddbb66ae
[apple/security.git] / OSX / libsecurity_asn1 / security_asn1 / prtypes.h
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 Mozilla Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/MPL/
7 *
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
12 *
13 * The Original Code is the Netscape Portable Runtime (NSPR).
14 *
15 * The Initial Developer of the Original Code is Netscape
16 * Communications Corporation. Portions created by Netscape are
17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All
18 * Rights Reserved.
19 *
20 * Contributor(s):
21 *
22 * Alternatively, the contents of this file may be used under the
23 * terms of the GNU General Public License Version 2 or later (the
24 * "GPL"), in which case the provisions of the GPL are applicable
25 * instead of those above. If you wish to allow use of your
26 * version of this file only under the terms of the GPL and not to
27 * allow others to use your version of this file under the MPL,
28 * indicate your decision by deleting the provisions above and
29 * replace them with the notice and other provisions required by
30 * the GPL. If you do not delete the provisions above, a recipient
31 * may use your version of this file under either the MPL or the
32 * GPL.
33 */
34
35 /*
36 ** File: prtypes.h
37 ** Description: Definitions of NSPR's basic types
38 **
39 ** Prototypes and macros used to make up for deficiencies in ANSI environments
40 ** that we have found.
41 **
42 ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
43 ** of portable code will not know in general that they need these definitions.
44 ** Instead of requiring these authors to find the dependent uses in their code
45 ** and take the following steps only in those C files, we take steps once here
46 ** for all C files.
47 **/
48
49 #ifndef prtypes_h___
50 #define prtypes_h___
51
52 #ifdef MDCPUCFG
53 #include MDCPUCFG
54 #else
55 #include <security_asn1/prcpucfg.h>
56 #endif
57
58 #include <stddef.h>
59
60 #ifdef __APPLE__
61 #include <stdint.h> // for uintptr_t
62 #endif
63
64 /***********************************************************************
65 ** MACROS: PR_EXTERN
66 ** PR_IMPLEMENT
67 ** DESCRIPTION:
68 ** These are only for externally visible routines and globals. For
69 ** internal routines, just use "extern" for type checking and that
70 ** will not export internal cross-file or forward-declared symbols.
71 ** Define a macro for declaring procedures return types. We use this to
72 ** deal with windoze specific type hackery for DLL definitions. Use
73 ** PR_EXTERN when the prototype for the method is declared. Use
74 ** PR_IMPLEMENT for the implementation of the method.
75 **
76 ** Example:
77 ** in dowhim.h
78 ** PR_EXTERN( void ) DoWhatIMean( void );
79 ** in dowhim.c
80 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
81 **
82 **
83 ***********************************************************************/
84 #if defined(WIN32)
85
86 #if defined(__GNUC__)
87 #undef _declspec
88 #define _declspec(x) __declspec(x)
89 #endif
90
91 #define PR_EXPORT(__type) extern _declspec(dllexport) __type
92 #define PR_EXPORT_DATA(__type) extern _declspec(dllexport) __type
93 #define PR_IMPORT(__type) _declspec(dllimport) __type
94 #define PR_IMPORT_DATA(__type) _declspec(dllimport) __type
95
96 #define PR_EXTERN(__type) extern _declspec(dllexport) __type
97 #define PR_IMPLEMENT(__type) _declspec(dllexport) __type
98 #define PR_EXTERN_DATA(__type) extern _declspec(dllexport) __type
99 #define PR_IMPLEMENT_DATA(__type) _declspec(dllexport) __type
100
101 #define PR_CALLBACK
102 #define PR_CALLBACK_DECL
103 #define PR_STATIC_CALLBACK(__x) static __x
104
105 #elif defined(XP_BEOS)
106
107 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
108 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
109 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
110 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
111
112 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
113 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
114 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
115 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
116
117 #define PR_CALLBACK
118 #define PR_CALLBACK_DECL
119 #define PR_STATIC_CALLBACK(__x) static __x
120
121 #elif defined(WIN16)
122
123 #define PR_CALLBACK_DECL __cdecl
124
125 #if defined(_WINDLL)
126 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
127 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
128 #define PR_EXPORT_DATA(__type) extern __type _export
129 #define PR_IMPORT_DATA(__type) extern __type _export
130
131 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
132 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
133 #define PR_EXTERN_DATA(__type) extern __type _export
134 #define PR_IMPLEMENT_DATA(__type) __type _export
135
136 #define PR_CALLBACK __cdecl __loadds
137 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
138
139 #else /* this must be .EXE */
140 #define PR_EXPORT(__type) extern __type _cdecl _export
141 #define PR_IMPORT(__type) extern __type _cdecl _export
142 #define PR_EXPORT_DATA(__type) extern __type _export
143 #define PR_IMPORT_DATA(__type) extern __type _export
144
145 #define PR_EXTERN(__type) extern __type _cdecl _export
146 #define PR_IMPLEMENT(__type) __type _cdecl _export
147 #define PR_EXTERN_DATA(__type) extern __type _export
148 #define PR_IMPLEMENT_DATA(__type) __type _export
149
150 #define PR_CALLBACK __cdecl __loadds
151 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
152 #endif /* _WINDLL */
153
154 #elif defined(XP_MAC)
155
156 #if defined __GNUC__
157 /* Darwin */
158 #define PR_EXPORT(__type) extern __type
159 #define PR_EXPORT_DATA(__type) extern __type
160 #define PR_IMPORT(__type) extern __type
161 #define PR_IMPORT_DATA(__type) extern __type
162
163 #define PR_EXTERN(__type) extern __type
164 #define PR_IMPLEMENT(__type) __type
165 #define PR_EXTERN_DATA(__type) extern __type
166 #define PR_IMPLEMENT_DATA(__type) __type
167 #define PR_CALLBACK
168 #define PR_CALLBACK_DECL
169 #define PR_STATIC_CALLBACK(__x) static __x
170
171 #else
172 /* MacOS 9 */
173 #define PR_EXPORT(__type) extern __declspec(export) __type
174 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
175 #define PR_IMPORT(__type) extern __declspec(export) __type
176 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
177
178 #define PR_EXTERN(__type) extern __declspec(export) __type
179 #define PR_IMPLEMENT(__type) __declspec(export) __type
180 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
181 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
182
183 #define PR_CALLBACK
184 #define PR_CALLBACK_DECL
185 #define PR_STATIC_CALLBACK(__x) static __x
186 #endif /* __GNUC__ */
187 #elif defined(XP_OS2_VACPP)
188
189 #define PR_EXPORT(__type) extern __type
190 #define PR_EXPORT_DATA(__type) extern __type
191 #define PR_IMPORT(__type) extern __type
192 #define PR_IMPORT_DATA(__type) extern __type
193
194 #define PR_EXTERN(__type) extern __type
195 #define PR_IMPLEMENT(__type) __type
196 #define PR_EXTERN_DATA(__type) extern __type
197 #define PR_IMPLEMENT_DATA(__type) __type
198 #define PR_CALLBACK _Optlink
199 #define PR_CALLBACK_DECL
200 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
201
202 #else /* Unix */
203
204 #define PR_EXPORT(__type) extern __type
205 #define PR_EXPORT_DATA(__type) extern __type
206 #define PR_IMPORT(__type) extern __type
207 #define PR_IMPORT_DATA(__type) extern __type
208
209 #define PR_EXTERN(__type) extern __type
210 #define PR_IMPLEMENT(__type) __type
211 #define PR_EXTERN_DATA(__type) extern __type
212 #define PR_IMPLEMENT_DATA(__type) __type
213 #define PR_CALLBACK
214 #define PR_CALLBACK_DECL
215 #define PR_STATIC_CALLBACK(__x) static __x
216
217 #endif
218
219 #if defined(_NSPR_BUILD_)
220 #define NSPR_API(__type) PR_EXPORT(__type)
221 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
222 #else
223 #define NSPR_API(__type) PR_IMPORT(__type)
224 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
225 #endif
226
227 /***********************************************************************
228 ** MACROS: PR_BEGIN_MACRO
229 ** PR_END_MACRO
230 ** DESCRIPTION:
231 ** Macro body brackets so that macros with compound statement definitions
232 ** behave syntactically more like functions when called.
233 ***********************************************************************/
234 #define PR_BEGIN_MACRO do {
235 #define PR_END_MACRO } while (0)
236
237 /***********************************************************************
238 ** MACROS: PR_BEGIN_EXTERN_C
239 ** PR_END_EXTERN_C
240 ** DESCRIPTION:
241 ** Macro shorthands for conditional C++ extern block delimiters.
242 ***********************************************************************/
243 #ifdef __cplusplus
244 #define PR_BEGIN_EXTERN_C extern "C" {
245 #define PR_END_EXTERN_C }
246 #else
247 #define PR_BEGIN_EXTERN_C
248 #define PR_END_EXTERN_C
249 #endif
250
251 /***********************************************************************
252 ** MACROS: PR_BIT
253 ** PR_BITMASK
254 ** DESCRIPTION:
255 ** Bit masking macros. XXX n must be <= 31 to be portable
256 ***********************************************************************/
257 #define PR_BIT(n) ((PRUint32)1 << (n))
258 #define PR_BITMASK(n) (PR_BIT(n) - 1)
259
260 /***********************************************************************
261 ** MACROS: PR_ROUNDUP
262 ** PR_MIN
263 ** PR_MAX
264 ** PR_ABS
265 ** DESCRIPTION:
266 ** Commonly used macros for operations on compatible types.
267 ***********************************************************************/
268 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
269 #define PR_MIN(x,y) ((x)<(y)?(x):(y))
270 #define PR_MAX(x,y) ((x)>(y)?(x):(y))
271 #define PR_ABS(x) ((x)<0?-(x):(x))
272
273 PR_BEGIN_EXTERN_C
274
275 /************************************************************************
276 ** TYPES: PRUint8
277 ** PRInt8
278 ** DESCRIPTION:
279 ** The int8 types are known to be 8 bits each. There is no type that
280 ** is equivalent to a plain "char".
281 ************************************************************************/
282 #if PR_BYTES_PER_BYTE == 1
283 typedef unsigned char PRUint8;
284 /*
285 ** Some cfront-based C++ compilers do not like 'signed char' and
286 ** issue the warning message:
287 ** warning: "signed" not implemented (ignored)
288 ** For these compilers, we have to define PRInt8 as plain 'char'.
289 ** Make sure that plain 'char' is indeed signed under these compilers.
290 */
291 #if (defined(HPUX) && defined(__cplusplus) \
292 && !defined(__GNUC__) && __cplusplus < 199707L) \
293 || (defined(SCO) && defined(__cplusplus) \
294 && !defined(__GNUC__) && __cplusplus == 1L)
295 typedef char PRInt8;
296 #else
297 typedef signed char PRInt8;
298 #endif
299 #else
300 #error No suitable type for PRInt8/PRUint8
301 #endif
302
303 /************************************************************************
304 * MACROS: PR_INT8_MAX
305 * PR_INT8_MIN
306 * PR_UINT8_MAX
307 * DESCRIPTION:
308 * The maximum and minimum values of a PRInt8 or PRUint8.
309 ************************************************************************/
310
311 #define PR_INT8_MAX 127
312 #define PR_INT8_MIN (-128)
313 #define PR_UINT8_MAX 255U
314
315 /************************************************************************
316 ** TYPES: PRUint16
317 ** PRInt16
318 ** DESCRIPTION:
319 ** The int16 types are known to be 16 bits each.
320 ************************************************************************/
321 #if PR_BYTES_PER_SHORT == 2
322 typedef unsigned short PRUint16;
323 typedef short PRInt16;
324 #else
325 #error No suitable type for PRInt16/PRUint16
326 #endif
327
328 /************************************************************************
329 * MACROS: PR_INT16_MAX
330 * PR_INT16_MIN
331 * PR_UINT16_MAX
332 * DESCRIPTION:
333 * The maximum and minimum values of a PRInt16 or PRUint16.
334 ************************************************************************/
335
336 #define PR_INT16_MAX 32767
337 #define PR_INT16_MIN (-32768)
338 #define PR_UINT16_MAX 65535U
339
340 /************************************************************************
341 ** TYPES: PRUint32
342 ** PRInt32
343 ** DESCRIPTION:
344 ** The int32 types are known to be 32 bits each.
345 ************************************************************************/
346 #if PR_BYTES_PER_INT == 4
347 typedef unsigned int PRUint32;
348 typedef int PRInt32;
349 #define PR_INT32(x) x
350 #define PR_UINT32(x) x ## U
351 #elif PR_BYTES_PER_LONG == 4
352 typedef unsigned long PRUint32;
353 typedef long PRInt32;
354 #define PR_INT32(x) x ## L
355 #define PR_UINT32(x) x ## UL
356 #else
357 #error No suitable type for PRInt32/PRUint32
358 #endif
359
360 /************************************************************************
361 * MACROS: PR_INT32_MAX
362 * PR_INT32_MIN
363 * PR_UINT32_MAX
364 * DESCRIPTION:
365 * The maximum and minimum values of a PRInt32 or PRUint32.
366 ************************************************************************/
367
368 #define PR_INT32_MAX PR_INT32(2147483647)
369 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
370 #define PR_UINT32_MAX PR_UINT32(4294967295)
371
372 /************************************************************************
373 ** TYPES: PRUint64
374 ** PRInt64
375 ** DESCRIPTION:
376 ** The int64 types are known to be 64 bits each. Care must be used when
377 ** declaring variables of type PRUint64 or PRInt64. Different hardware
378 ** architectures and even different compilers have varying support for
379 ** 64 bit values. The only guaranteed portability requires the use of
380 ** the LL_ macros (see prlong.h).
381 ************************************************************************/
382 #ifdef HAVE_LONG_LONG
383 #if PR_BYTES_PER_LONG == 8
384 typedef long PRInt64;
385 typedef unsigned long PRUint64;
386 #elif defined(WIN16)
387 typedef __int64 PRInt64;
388 typedef unsigned __int64 PRUint64;
389 #elif defined(WIN32) && !defined(__GNUC__)
390 typedef __int64 PRInt64;
391 typedef unsigned __int64 PRUint64;
392 #else
393 typedef long long PRInt64;
394 typedef unsigned long long PRUint64;
395 #endif /* PR_BYTES_PER_LONG == 8 */
396 #else /* !HAVE_LONG_LONG */
397 typedef struct {
398 #ifdef IS_LITTLE_ENDIAN
399 PRUint32 lo, hi;
400 #else
401 PRUint32 hi, lo;
402 #endif
403 } PRInt64;
404 typedef PRInt64 PRUint64;
405 #endif /* !HAVE_LONG_LONG */
406
407 /************************************************************************
408 ** TYPES: PRUintn
409 ** PRIntn
410 ** DESCRIPTION:
411 ** The PRIntn types are most appropriate for automatic variables. They are
412 ** guaranteed to be at least 16 bits, though various architectures may
413 ** define them to be wider (e.g., 32 or even 64 bits). These types are
414 ** never valid for fields of a structure.
415 ************************************************************************/
416 #if PR_BYTES_PER_INT >= 2
417 typedef int PRIntn;
418 typedef unsigned int PRUintn;
419 #else
420 #error 'sizeof(int)' not sufficient for platform use
421 #endif
422
423 /************************************************************************
424 ** TYPES: PRFloat64
425 ** DESCRIPTION:
426 ** NSPR's floating point type is always 64 bits.
427 ************************************************************************/
428 typedef double PRFloat64;
429
430 /************************************************************************
431 ** TYPES: PRSize
432 ** DESCRIPTION:
433 ** A type for representing the size of objects.
434 ************************************************************************/
435 typedef size_t PRSize;
436
437
438 /************************************************************************
439 ** TYPES: PROffset32, PROffset64
440 ** DESCRIPTION:
441 ** A type for representing byte offsets from some location.
442 ************************************************************************/
443 typedef PRInt32 PROffset32;
444 typedef PRInt64 PROffset64;
445
446 /************************************************************************
447 ** TYPES: PRPtrDiff
448 ** DESCRIPTION:
449 ** A type for pointer difference. Variables of this type are suitable
450 ** for storing a pointer or pointer sutraction.
451 ************************************************************************/
452 typedef ptrdiff_t PRPtrdiff;
453
454 /************************************************************************
455 ** TYPES: PRUptrdiff
456 ** DESCRIPTION:
457 ** A type for pointer difference. Variables of this type are suitable
458 ** for storing a pointer or pointer sutraction.
459 ************************************************************************/
460 typedef unsigned long PRUptrdiff;
461
462 /************************************************************************
463 ** TYPES: PRBool
464 ** DESCRIPTION:
465 ** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
466 ** for clarity of target type in assignments and actual arguments. Use
467 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
468 ** juast as you would C int-valued conditions.
469 ************************************************************************/
470 typedef PRIntn PRBool;
471 #define PR_TRUE 1
472 #define PR_FALSE 0
473
474 /************************************************************************
475 ** TYPES: PRPackedBool
476 ** DESCRIPTION:
477 ** Use PRPackedBOol within structs where bitfields are not desireable
478 ** but minimum and consistant overhead matters.
479 ************************************************************************/
480 typedef PRUint8 PRPackedBool;
481
482 /*
483 ** Status code used by some routines that have a single point of failure or
484 ** special status return.
485 */
486 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
487
488 #ifdef MOZ_UNICODE
489 /*
490 * EXPERIMENTAL: This type may be removed in a future release.
491 */
492 #ifndef __PRUNICHAR__
493 #define __PRUNICHAR__
494 #if defined(WIN32) || defined(XP_MAC)
495 typedef wchar_t PRUnichar;
496 #else
497 typedef PRUint16 PRUnichar;
498 #endif
499 #endif
500 #endif /* MOZ_UNICODE */
501
502 /*
503 ** WARNING: The undocumented data types PRWord and PRUword are
504 ** only used in the garbage collection and arena code. Do not
505 ** use PRWord and PRUword in new code.
506 **
507 ** A PRWord is an integer that is the same size as a void*.
508 ** It implements the notion of a "word" in the Java Virtual
509 ** Machine. (See Sec. 3.4 "Words", The Java Virtual Machine
510 ** Specification, Addison-Wesley, September 1996.
511 ** http://java.sun.com/docs/books/vmspec/index.html.)
512 */
513
514 #ifdef __APPLE__
515 typedef intptr_t PRWord;
516 typedef uintptr_t PRUword;
517 #else
518 typedef long PRWord;
519 typedef unsigned long PRUword;
520 #endif
521
522 #if defined(NO_NSPR_10_SUPPORT)
523 #else
524 /********* ???????????????? FIX ME ??????????????????????????? *****/
525 /********************** Some old definitions until pr=>ds transition is done ***/
526 /********************** Also, we are still using NSPR 1.0. GC ******************/
527 /*
528 ** Fundamental NSPR macros, used nearly everywhere.
529 */
530
531 #define PR_PUBLIC_API PR_IMPLEMENT
532
533 /*
534 ** Macro body brackets so that macros with compound statement definitions
535 ** behave syntactically more like functions when called.
536 */
537 #define NSPR_BEGIN_MACRO do {
538 #define NSPR_END_MACRO } while (0)
539
540 /*
541 ** Macro shorthands for conditional C++ extern block delimiters.
542 */
543 #ifdef NSPR_BEGIN_EXTERN_C
544 #undef NSPR_BEGIN_EXTERN_C
545 #endif
546 #ifdef NSPR_END_EXTERN_C
547 #undef NSPR_END_EXTERN_C
548 #endif
549
550 #ifdef __cplusplus
551 #define NSPR_BEGIN_EXTERN_C extern "C" {
552 #define NSPR_END_EXTERN_C }
553 #else
554 #define NSPR_BEGIN_EXTERN_C
555 #define NSPR_END_EXTERN_C
556 #endif
557
558 #ifdef XP_MAC
559 #include "protypes.h"
560 #else
561 #include "obsolete/protypes.h"
562 #endif
563
564 /********* ????????????? End Fix me ?????????????????????????????? *****/
565 #endif /* NO_NSPR_10_SUPPORT */
566
567 PR_END_EXTERN_C
568
569 #endif /* prtypes_h___ */
570