]>
git.saurik.com Git - apple/security.git/blob - libsecurity_asn1/lib/prtypes.h
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>
60 /***********************************************************************
64 ** These are only for externally visible routines and globals. For
65 ** internal routines, just use "extern" for type checking and that
66 ** will not export internal cross-file or forward-declared symbols.
67 ** Define a macro for declaring procedures return types. We use this to
68 ** deal with windoze specific type hackery for DLL definitions. Use
69 ** PR_EXTERN when the prototype for the method is declared. Use
70 ** PR_IMPLEMENT for the implementation of the method.
74 ** PR_EXTERN( void ) DoWhatIMean( void );
76 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
79 ***********************************************************************/
84 #define _declspec(x) __declspec(x)
87 #define PR_EXPORT(__type) extern _declspec(dllexport) __type
88 #define PR_EXPORT_DATA(__type) extern _declspec(dllexport) __type
89 #define PR_IMPORT(__type) _declspec(dllimport) __type
90 #define PR_IMPORT_DATA(__type) _declspec(dllimport) __type
92 #define PR_EXTERN(__type) extern _declspec(dllexport) __type
93 #define PR_IMPLEMENT(__type) _declspec(dllexport) __type
94 #define PR_EXTERN_DATA(__type) extern _declspec(dllexport) __type
95 #define PR_IMPLEMENT_DATA(__type) _declspec(dllexport) __type
98 #define PR_CALLBACK_DECL
99 #define PR_STATIC_CALLBACK(__x) static __x
101 #elif defined(XP_BEOS)
103 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
104 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
105 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
106 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
108 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
109 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
110 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
111 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
114 #define PR_CALLBACK_DECL
115 #define PR_STATIC_CALLBACK(__x) static __x
119 #define PR_CALLBACK_DECL __cdecl
122 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
123 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
124 #define PR_EXPORT_DATA(__type) extern __type _export
125 #define PR_IMPORT_DATA(__type) extern __type _export
127 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
128 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
129 #define PR_EXTERN_DATA(__type) extern __type _export
130 #define PR_IMPLEMENT_DATA(__type) __type _export
132 #define PR_CALLBACK __cdecl __loadds
133 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
135 #else /* this must be .EXE */
136 #define PR_EXPORT(__type) extern __type _cdecl _export
137 #define PR_IMPORT(__type) extern __type _cdecl _export
138 #define PR_EXPORT_DATA(__type) extern __type _export
139 #define PR_IMPORT_DATA(__type) extern __type _export
141 #define PR_EXTERN(__type) extern __type _cdecl _export
142 #define PR_IMPLEMENT(__type) __type _cdecl _export
143 #define PR_EXTERN_DATA(__type) extern __type _export
144 #define PR_IMPLEMENT_DATA(__type) __type _export
146 #define PR_CALLBACK __cdecl __loadds
147 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
150 #elif defined(XP_MAC)
154 #define PR_EXPORT(__type) extern __type
155 #define PR_EXPORT_DATA(__type) extern __type
156 #define PR_IMPORT(__type) extern __type
157 #define PR_IMPORT_DATA(__type) extern __type
159 #define PR_EXTERN(__type) extern __type
160 #define PR_IMPLEMENT(__type) __type
161 #define PR_EXTERN_DATA(__type) extern __type
162 #define PR_IMPLEMENT_DATA(__type) __type
164 #define PR_CALLBACK_DECL
165 #define PR_STATIC_CALLBACK(__x) static __x
169 #define PR_EXPORT(__type) extern __declspec(export) __type
170 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
171 #define PR_IMPORT(__type) extern __declspec(export) __type
172 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
174 #define PR_EXTERN(__type) extern __declspec(export) __type
175 #define PR_IMPLEMENT(__type) __declspec(export) __type
176 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
177 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
180 #define PR_CALLBACK_DECL
181 #define PR_STATIC_CALLBACK(__x) static __x
182 #endif /* __GNUC__ */
183 #elif defined(XP_OS2_VACPP)
185 #define PR_EXPORT(__type) extern __type
186 #define PR_EXPORT_DATA(__type) extern __type
187 #define PR_IMPORT(__type) extern __type
188 #define PR_IMPORT_DATA(__type) extern __type
190 #define PR_EXTERN(__type) extern __type
191 #define PR_IMPLEMENT(__type) __type
192 #define PR_EXTERN_DATA(__type) extern __type
193 #define PR_IMPLEMENT_DATA(__type) __type
194 #define PR_CALLBACK _Optlink
195 #define PR_CALLBACK_DECL
196 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
200 #define PR_EXPORT(__type) extern __type
201 #define PR_EXPORT_DATA(__type) extern __type
202 #define PR_IMPORT(__type) extern __type
203 #define PR_IMPORT_DATA(__type) extern __type
205 #define PR_EXTERN(__type) extern __type
206 #define PR_IMPLEMENT(__type) __type
207 #define PR_EXTERN_DATA(__type) extern __type
208 #define PR_IMPLEMENT_DATA(__type) __type
210 #define PR_CALLBACK_DECL
211 #define PR_STATIC_CALLBACK(__x) static __x
215 #if defined(_NSPR_BUILD_)
216 #define NSPR_API(__type) PR_EXPORT(__type)
217 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
219 #define NSPR_API(__type) PR_IMPORT(__type)
220 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
223 /***********************************************************************
224 ** MACROS: PR_BEGIN_MACRO
227 ** Macro body brackets so that macros with compound statement definitions
228 ** behave syntactically more like functions when called.
229 ***********************************************************************/
230 #define PR_BEGIN_MACRO do {
231 #define PR_END_MACRO } while (0)
233 /***********************************************************************
234 ** MACROS: PR_BEGIN_EXTERN_C
237 ** Macro shorthands for conditional C++ extern block delimiters.
238 ***********************************************************************/
240 #define PR_BEGIN_EXTERN_C extern "C" {
241 #define PR_END_EXTERN_C }
243 #define PR_BEGIN_EXTERN_C
244 #define PR_END_EXTERN_C
247 /***********************************************************************
251 ** Bit masking macros. XXX n must be <= 31 to be portable
252 ***********************************************************************/
253 #define PR_BIT(n) ((PRUint32)1 << (n))
254 #define PR_BITMASK(n) (PR_BIT(n) - 1)
256 /***********************************************************************
257 ** MACROS: PR_ROUNDUP
262 ** Commonly used macros for operations on compatible types.
263 ***********************************************************************/
264 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
265 #define PR_MIN(x,y) ((x)<(y)?(x):(y))
266 #define PR_MAX(x,y) ((x)>(y)?(x):(y))
267 #define PR_ABS(x) ((x)<0?-(x):(x))
271 /************************************************************************
275 ** The int8 types are known to be 8 bits each. There is no type that
276 ** is equivalent to a plain "char".
277 ************************************************************************/
278 #if PR_BYTES_PER_BYTE == 1
279 typedef unsigned char PRUint8
;
281 ** Some cfront-based C++ compilers do not like 'signed char' and
282 ** issue the warning message:
283 ** warning: "signed" not implemented (ignored)
284 ** For these compilers, we have to define PRInt8 as plain 'char'.
285 ** Make sure that plain 'char' is indeed signed under these compilers.
287 #if (defined(HPUX) && defined(__cplusplus) \
288 && !defined(__GNUC__) && __cplusplus < 199707L) \
289 || (defined(SCO) && defined(__cplusplus) \
290 && !defined(__GNUC__) && __cplusplus == 1L)
293 typedef signed char PRInt8
;
296 #error No suitable type for PRInt8/PRUint8
299 /************************************************************************
300 * MACROS: PR_INT8_MAX
304 * The maximum and minimum values of a PRInt8 or PRUint8.
305 ************************************************************************/
307 #define PR_INT8_MAX 127
308 #define PR_INT8_MIN (-128)
309 #define PR_UINT8_MAX 255U
311 /************************************************************************
315 ** The int16 types are known to be 16 bits each.
316 ************************************************************************/
317 #if PR_BYTES_PER_SHORT == 2
318 typedef unsigned short PRUint16
;
319 typedef short PRInt16
;
321 #error No suitable type for PRInt16/PRUint16
324 /************************************************************************
325 * MACROS: PR_INT16_MAX
329 * The maximum and minimum values of a PRInt16 or PRUint16.
330 ************************************************************************/
332 #define PR_INT16_MAX 32767
333 #define PR_INT16_MIN (-32768)
334 #define PR_UINT16_MAX 65535U
336 /************************************************************************
340 ** The int32 types are known to be 32 bits each.
341 ************************************************************************/
342 #if PR_BYTES_PER_INT == 4
343 typedef unsigned int PRUint32
;
345 #define PR_INT32(x) x
346 #define PR_UINT32(x) x ## U
347 #elif PR_BYTES_PER_LONG == 4
348 typedef unsigned long PRUint32
;
349 typedef long PRInt32
;
350 #define PR_INT32(x) x ## L
351 #define PR_UINT32(x) x ## UL
353 #error No suitable type for PRInt32/PRUint32
356 /************************************************************************
357 * MACROS: PR_INT32_MAX
361 * The maximum and minimum values of a PRInt32 or PRUint32.
362 ************************************************************************/
364 #define PR_INT32_MAX PR_INT32(2147483647)
365 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
366 #define PR_UINT32_MAX PR_UINT32(4294967295)
368 /************************************************************************
372 ** The int64 types are known to be 64 bits each. Care must be used when
373 ** declaring variables of type PRUint64 or PRInt64. Different hardware
374 ** architectures and even different compilers have varying support for
375 ** 64 bit values. The only guaranteed portability requires the use of
376 ** the LL_ macros (see prlong.h).
377 ************************************************************************/
378 #ifdef HAVE_LONG_LONG
379 #if PR_BYTES_PER_LONG == 8
380 typedef long PRInt64
;
381 typedef unsigned long PRUint64
;
383 typedef __int64 PRInt64
;
384 typedef unsigned __int64 PRUint64
;
385 #elif defined(WIN32) && !defined(__GNUC__)
386 typedef __int64 PRInt64
;
387 typedef unsigned __int64 PRUint64
;
389 typedef long long PRInt64
;
390 typedef unsigned long long PRUint64
;
391 #endif /* PR_BYTES_PER_LONG == 8 */
392 #else /* !HAVE_LONG_LONG */
394 #ifdef IS_LITTLE_ENDIAN
400 typedef PRInt64 PRUint64
;
401 #endif /* !HAVE_LONG_LONG */
403 /************************************************************************
407 ** The PRIntn types are most appropriate for automatic variables. They are
408 ** guaranteed to be at least 16 bits, though various architectures may
409 ** define them to be wider (e.g., 32 or even 64 bits). These types are
410 ** never valid for fields of a structure.
411 ************************************************************************/
412 #if PR_BYTES_PER_INT >= 2
414 typedef unsigned int PRUintn
;
416 #error 'sizeof(int)' not sufficient for platform use
419 /************************************************************************
422 ** NSPR's floating point type is always 64 bits.
423 ************************************************************************/
424 typedef double PRFloat64
;
426 /************************************************************************
429 ** A type for representing the size of objects.
430 ************************************************************************/
431 typedef size_t PRSize
;
434 /************************************************************************
435 ** TYPES: PROffset32, PROffset64
437 ** A type for representing byte offsets from some location.
438 ************************************************************************/
439 typedef PRInt32 PROffset32
;
440 typedef PRInt64 PROffset64
;
442 /************************************************************************
445 ** A type for pointer difference. Variables of this type are suitable
446 ** for storing a pointer or pointer sutraction.
447 ************************************************************************/
448 typedef ptrdiff_t PRPtrdiff
;
450 /************************************************************************
453 ** A type for pointer difference. Variables of this type are suitable
454 ** for storing a pointer or pointer sutraction.
455 ************************************************************************/
456 typedef unsigned long PRUptrdiff
;
458 /************************************************************************
461 ** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
462 ** for clarity of target type in assignments and actual arguments. Use
463 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
464 ** juast as you would C int-valued conditions.
465 ************************************************************************/
466 typedef PRIntn PRBool
;
470 /************************************************************************
471 ** TYPES: PRPackedBool
473 ** Use PRPackedBOol within structs where bitfields are not desireable
474 ** but minimum and consistant overhead matters.
475 ************************************************************************/
476 typedef PRUint8 PRPackedBool
;
479 ** Status code used by some routines that have a single point of failure or
480 ** special status return.
482 typedef enum { PR_FAILURE
= -1, PR_SUCCESS
= 0 } PRStatus
;
486 * EXPERIMENTAL: This type may be removed in a future release.
488 #ifndef __PRUNICHAR__
489 #define __PRUNICHAR__
490 #if defined(WIN32) || defined(XP_MAC)
491 typedef wchar_t PRUnichar
;
493 typedef PRUint16 PRUnichar
;
496 #endif /* MOZ_UNICODE */
499 ** WARNING: The undocumented data types PRWord and PRUword are
500 ** only used in the garbage collection and arena code. Do not
501 ** use PRWord and PRUword in new code.
503 ** A PRWord is an integer that is the same size as a void*.
504 ** It implements the notion of a "word" in the Java Virtual
505 ** Machine. (See Sec. 3.4 "Words", The Java Virtual Machine
506 ** Specification, Addison-Wesley, September 1996.
507 ** http://java.sun.com/docs/books/vmspec/index.html.)
510 typedef size_t PRUword
;
512 #if defined(NO_NSPR_10_SUPPORT)
514 /********* ???????????????? FIX ME ??????????????????????????? *****/
515 /********************** Some old definitions until pr=>ds transition is done ***/
516 /********************** Also, we are still using NSPR 1.0. GC ******************/
518 ** Fundamental NSPR macros, used nearly everywhere.
521 #define PR_PUBLIC_API PR_IMPLEMENT
524 ** Macro body brackets so that macros with compound statement definitions
525 ** behave syntactically more like functions when called.
527 #define NSPR_BEGIN_MACRO do {
528 #define NSPR_END_MACRO } while (0)
531 ** Macro shorthands for conditional C++ extern block delimiters.
533 #ifdef NSPR_BEGIN_EXTERN_C
534 #undef NSPR_BEGIN_EXTERN_C
536 #ifdef NSPR_END_EXTERN_C
537 #undef NSPR_END_EXTERN_C
541 #define NSPR_BEGIN_EXTERN_C extern "C" {
542 #define NSPR_END_EXTERN_C }
544 #define NSPR_BEGIN_EXTERN_C
545 #define NSPR_END_EXTERN_C
549 #include "protypes.h"
551 #include "obsolete/protypes.h"
554 /********* ????????????? End Fix me ?????????????????????????????? *****/
555 #endif /* NO_NSPR_10_SUPPORT */
559 #endif /* prtypes_h___ */