]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_asn1/security_asn1/prtypes.h
441ca69618e6467c1184aa3ded0286bbddbb66ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/
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.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
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
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
37 ** Description: Definitions of NSPR's basic types
39 ** Prototypes and macros used to make up for deficiencies in ANSI environments
40 ** that we have found.
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
55 #include <security_asn1/prcpucfg.h>
61 #include <stdint.h> // for uintptr_t
64 /***********************************************************************
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.
78 ** PR_EXTERN( void ) DoWhatIMean( void );
80 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
83 ***********************************************************************/
88 #define _declspec(x) __declspec(x)
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
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
102 #define PR_CALLBACK_DECL
103 #define PR_STATIC_CALLBACK(__x) static __x
105 #elif defined(XP_BEOS)
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
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
118 #define PR_CALLBACK_DECL
119 #define PR_STATIC_CALLBACK(__x) static __x
123 #define PR_CALLBACK_DECL __cdecl
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
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
136 #define PR_CALLBACK __cdecl __loadds
137 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
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
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
150 #define PR_CALLBACK __cdecl __loadds
151 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
154 #elif defined(XP_MAC)
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
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
168 #define PR_CALLBACK_DECL
169 #define PR_STATIC_CALLBACK(__x) static __x
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
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
184 #define PR_CALLBACK_DECL
185 #define PR_STATIC_CALLBACK(__x) static __x
186 #endif /* __GNUC__ */
187 #elif defined(XP_OS2_VACPP)
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
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
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
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
214 #define PR_CALLBACK_DECL
215 #define PR_STATIC_CALLBACK(__x) static __x
219 #if defined(_NSPR_BUILD_)
220 #define NSPR_API(__type) PR_EXPORT(__type)
221 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
223 #define NSPR_API(__type) PR_IMPORT(__type)
224 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
227 /***********************************************************************
228 ** MACROS: PR_BEGIN_MACRO
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)
237 /***********************************************************************
238 ** MACROS: PR_BEGIN_EXTERN_C
241 ** Macro shorthands for conditional C++ extern block delimiters.
242 ***********************************************************************/
244 #define PR_BEGIN_EXTERN_C extern "C" {
245 #define PR_END_EXTERN_C }
247 #define PR_BEGIN_EXTERN_C
248 #define PR_END_EXTERN_C
251 /***********************************************************************
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)
260 /***********************************************************************
261 ** MACROS: PR_ROUNDUP
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))
275 /************************************************************************
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
;
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.
291 #if (defined(HPUX) && defined(__cplusplus) \
292 && !defined(__GNUC__) && __cplusplus < 199707L) \
293 || (defined(SCO) && defined(__cplusplus) \
294 && !defined(__GNUC__) && __cplusplus == 1L)
297 typedef signed char PRInt8
;
300 #error No suitable type for PRInt8/PRUint8
303 /************************************************************************
304 * MACROS: PR_INT8_MAX
308 * The maximum and minimum values of a PRInt8 or PRUint8.
309 ************************************************************************/
311 #define PR_INT8_MAX 127
312 #define PR_INT8_MIN (-128)
313 #define PR_UINT8_MAX 255U
315 /************************************************************************
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
;
325 #error No suitable type for PRInt16/PRUint16
328 /************************************************************************
329 * MACROS: PR_INT16_MAX
333 * The maximum and minimum values of a PRInt16 or PRUint16.
334 ************************************************************************/
336 #define PR_INT16_MAX 32767
337 #define PR_INT16_MIN (-32768)
338 #define PR_UINT16_MAX 65535U
340 /************************************************************************
344 ** The int32 types are known to be 32 bits each.
345 ************************************************************************/
346 #if PR_BYTES_PER_INT == 4
347 typedef unsigned int PRUint32
;
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
357 #error No suitable type for PRInt32/PRUint32
360 /************************************************************************
361 * MACROS: PR_INT32_MAX
365 * The maximum and minimum values of a PRInt32 or PRUint32.
366 ************************************************************************/
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)
372 /************************************************************************
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
;
387 typedef __int64 PRInt64
;
388 typedef unsigned __int64 PRUint64
;
389 #elif defined(WIN32) && !defined(__GNUC__)
390 typedef __int64 PRInt64
;
391 typedef unsigned __int64 PRUint64
;
393 typedef long long PRInt64
;
394 typedef unsigned long long PRUint64
;
395 #endif /* PR_BYTES_PER_LONG == 8 */
396 #else /* !HAVE_LONG_LONG */
398 #ifdef IS_LITTLE_ENDIAN
404 typedef PRInt64 PRUint64
;
405 #endif /* !HAVE_LONG_LONG */
407 /************************************************************************
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
418 typedef unsigned int PRUintn
;
420 #error 'sizeof(int)' not sufficient for platform use
423 /************************************************************************
426 ** NSPR's floating point type is always 64 bits.
427 ************************************************************************/
428 typedef double PRFloat64
;
430 /************************************************************************
433 ** A type for representing the size of objects.
434 ************************************************************************/
435 typedef size_t PRSize
;
438 /************************************************************************
439 ** TYPES: PROffset32, PROffset64
441 ** A type for representing byte offsets from some location.
442 ************************************************************************/
443 typedef PRInt32 PROffset32
;
444 typedef PRInt64 PROffset64
;
446 /************************************************************************
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
;
454 /************************************************************************
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
;
462 /************************************************************************
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
;
474 /************************************************************************
475 ** TYPES: PRPackedBool
477 ** Use PRPackedBOol within structs where bitfields are not desireable
478 ** but minimum and consistant overhead matters.
479 ************************************************************************/
480 typedef PRUint8 PRPackedBool
;
483 ** Status code used by some routines that have a single point of failure or
484 ** special status return.
486 typedef enum { PR_FAILURE
= -1, PR_SUCCESS
= 0 } PRStatus
;
490 * EXPERIMENTAL: This type may be removed in a future release.
492 #ifndef __PRUNICHAR__
493 #define __PRUNICHAR__
494 #if defined(WIN32) || defined(XP_MAC)
495 typedef wchar_t PRUnichar
;
497 typedef PRUint16 PRUnichar
;
500 #endif /* MOZ_UNICODE */
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.
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.)
515 typedef intptr_t PRWord
;
516 typedef uintptr_t PRUword
;
519 typedef unsigned long PRUword
;
522 #if defined(NO_NSPR_10_SUPPORT)
524 /********* ???????????????? FIX ME ??????????????????????????? *****/
525 /********************** Some old definitions until pr=>ds transition is done ***/
526 /********************** Also, we are still using NSPR 1.0. GC ******************/
528 ** Fundamental NSPR macros, used nearly everywhere.
531 #define PR_PUBLIC_API PR_IMPLEMENT
534 ** Macro body brackets so that macros with compound statement definitions
535 ** behave syntactically more like functions when called.
537 #define NSPR_BEGIN_MACRO do {
538 #define NSPR_END_MACRO } while (0)
541 ** Macro shorthands for conditional C++ extern block delimiters.
543 #ifdef NSPR_BEGIN_EXTERN_C
544 #undef NSPR_BEGIN_EXTERN_C
546 #ifdef NSPR_END_EXTERN_C
547 #undef NSPR_END_EXTERN_C
551 #define NSPR_BEGIN_EXTERN_C extern "C" {
552 #define NSPR_END_EXTERN_C }
554 #define NSPR_BEGIN_EXTERN_C
555 #define NSPR_END_EXTERN_C
559 #include "protypes.h"
561 #include "obsolete/protypes.h"
564 /********* ????????????? End Fix me ?????????????????????????????? *****/
565 #endif /* NO_NSPR_10_SUPPORT */
569 #endif /* prtypes_h___ */