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/*********************************************************************** 61** MACROS: PR_EXTERN 62** PR_IMPLEMENT 63** DESCRIPTION: 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. 71** 72** Example: 73** in dowhim.h 74** PR_EXTERN( void ) DoWhatIMean( void ); 75** in dowhim.c 76** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; } 77** 78** 79***********************************************************************/ 80#if defined(WIN32) 81 82#if defined(__GNUC__) 83#undef _declspec 84#define _declspec(x) __declspec(x) 85#endif 86 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 91 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 96 97#define PR_CALLBACK 98#define PR_CALLBACK_DECL 99#define PR_STATIC_CALLBACK(__x) static __x 100 101#elif defined(XP_BEOS) 102 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 107 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 112 113#define PR_CALLBACK 114#define PR_CALLBACK_DECL 115#define PR_STATIC_CALLBACK(__x) static __x 116 117#elif defined(WIN16) 118 119#define PR_CALLBACK_DECL __cdecl 120 121#if defined(_WINDLL) 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 126 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 131 132#define PR_CALLBACK __cdecl __loadds 133#define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK 134 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 140 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 145 146#define PR_CALLBACK __cdecl __loadds 147#define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK 148#endif /* _WINDLL */ 149 150#elif defined(XP_MAC) 151 152 #if defined __GNUC__ 153 /* Darwin */ 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 158 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 163 #define PR_CALLBACK 164 #define PR_CALLBACK_DECL 165 #define PR_STATIC_CALLBACK(__x) static __x 166 167 #else 168 /* MacOS 9 */ 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 173 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 178 179 #define PR_CALLBACK 180 #define PR_CALLBACK_DECL 181 #define PR_STATIC_CALLBACK(__x) static __x 182 #endif /* __GNUC__ */ 183#elif defined(XP_OS2_VACPP) 184 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 189 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 197 198#else /* Unix */ 199 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 204 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 209#define PR_CALLBACK 210#define PR_CALLBACK_DECL 211#define PR_STATIC_CALLBACK(__x) static __x 212 213#endif 214 215#if defined(_NSPR_BUILD_) 216#define NSPR_API(__type) PR_EXPORT(__type) 217#define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type) 218#else 219#define NSPR_API(__type) PR_IMPORT(__type) 220#define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type) 221#endif 222 223/*********************************************************************** 224** MACROS: PR_BEGIN_MACRO 225** PR_END_MACRO 226** DESCRIPTION: 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) 232 233/*********************************************************************** 234** MACROS: PR_BEGIN_EXTERN_C 235** PR_END_EXTERN_C 236** DESCRIPTION: 237** Macro shorthands for conditional C++ extern block delimiters. 238***********************************************************************/ 239#ifdef __cplusplus 240#define PR_BEGIN_EXTERN_C extern "C" { 241#define PR_END_EXTERN_C } 242#else 243#define PR_BEGIN_EXTERN_C 244#define PR_END_EXTERN_C 245#endif 246 247/*********************************************************************** 248** MACROS: PR_BIT 249** PR_BITMASK 250** DESCRIPTION: 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) 255 256/*********************************************************************** 257** MACROS: PR_ROUNDUP 258** PR_MIN 259** PR_MAX 260** PR_ABS 261** DESCRIPTION: 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)) 268 269PR_BEGIN_EXTERN_C 270 271/************************************************************************ 272** TYPES: PRUint8 273** PRInt8 274** DESCRIPTION: 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 279typedef unsigned char PRUint8; 280/* 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. 286*/ 287#if (defined(HPUX) && defined(__cplusplus) \ 288 && !defined(__GNUC__) && __cplusplus < 199707L) \ 289 || (defined(SCO) && defined(__cplusplus) \ 290 && !defined(__GNUC__) && __cplusplus == 1L) 291typedef char PRInt8; 292#else 293typedef signed char PRInt8; 294#endif 295#else 296#error No suitable type for PRInt8/PRUint8 297#endif 298 299/************************************************************************ 300 * MACROS: PR_INT8_MAX 301 * PR_INT8_MIN 302 * PR_UINT8_MAX 303 * DESCRIPTION: 304 * The maximum and minimum values of a PRInt8 or PRUint8. 305************************************************************************/ 306 307#define PR_INT8_MAX 127 308#define PR_INT8_MIN (-128) 309#define PR_UINT8_MAX 255U 310 311/************************************************************************ 312** TYPES: PRUint16 313** PRInt16 314** DESCRIPTION: 315** The int16 types are known to be 16 bits each. 316************************************************************************/ 317#if PR_BYTES_PER_SHORT == 2 318typedef unsigned short PRUint16; 319typedef short PRInt16; 320#else 321#error No suitable type for PRInt16/PRUint16 322#endif 323 324/************************************************************************ 325 * MACROS: PR_INT16_MAX 326 * PR_INT16_MIN 327 * PR_UINT16_MAX 328 * DESCRIPTION: 329 * The maximum and minimum values of a PRInt16 or PRUint16. 330************************************************************************/ 331 332#define PR_INT16_MAX 32767 333#define PR_INT16_MIN (-32768) 334#define PR_UINT16_MAX 65535U 335 336/************************************************************************ 337** TYPES: PRUint32 338** PRInt32 339** DESCRIPTION: 340** The int32 types are known to be 32 bits each. 341************************************************************************/ 342#if PR_BYTES_PER_INT == 4 343typedef unsigned int PRUint32; 344typedef int PRInt32; 345#define PR_INT32(x) x 346#define PR_UINT32(x) x ## U 347#elif PR_BYTES_PER_LONG == 4 348typedef unsigned long PRUint32; 349typedef long PRInt32; 350#define PR_INT32(x) x ## L 351#define PR_UINT32(x) x ## UL 352#else 353#error No suitable type for PRInt32/PRUint32 354#endif 355 356/************************************************************************ 357 * MACROS: PR_INT32_MAX 358 * PR_INT32_MIN 359 * PR_UINT32_MAX 360 * DESCRIPTION: 361 * The maximum and minimum values of a PRInt32 or PRUint32. 362************************************************************************/ 363 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) 367 368/************************************************************************ 369** TYPES: PRUint64 370** PRInt64 371** DESCRIPTION: 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 380typedef long PRInt64; 381typedef unsigned long PRUint64; 382#elif defined(WIN16) 383typedef __int64 PRInt64; 384typedef unsigned __int64 PRUint64; 385#elif defined(WIN32) && !defined(__GNUC__) 386typedef __int64 PRInt64; 387typedef unsigned __int64 PRUint64; 388#else 389typedef long long PRInt64; 390typedef unsigned long long PRUint64; 391#endif /* PR_BYTES_PER_LONG == 8 */ 392#else /* !HAVE_LONG_LONG */ 393typedef struct { 394#ifdef IS_LITTLE_ENDIAN 395 PRUint32 lo, hi; 396#else 397 PRUint32 hi, lo; 398#endif 399} PRInt64; 400typedef PRInt64 PRUint64; 401#endif /* !HAVE_LONG_LONG */ 402 403/************************************************************************ 404** TYPES: PRUintn 405** PRIntn 406** DESCRIPTION: 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 413typedef int PRIntn; 414typedef unsigned int PRUintn; 415#else 416#error 'sizeof(int)' not sufficient for platform use 417#endif 418 419/************************************************************************ 420** TYPES: PRFloat64 421** DESCRIPTION: 422** NSPR's floating point type is always 64 bits. 423************************************************************************/ 424typedef double PRFloat64; 425 426/************************************************************************ 427** TYPES: PRSize 428** DESCRIPTION: 429** A type for representing the size of objects. 430************************************************************************/ 431typedef size_t PRSize; 432 433 434/************************************************************************ 435** TYPES: PROffset32, PROffset64 436** DESCRIPTION: 437** A type for representing byte offsets from some location. 438************************************************************************/ 439typedef PRInt32 PROffset32; 440typedef PRInt64 PROffset64; 441 442/************************************************************************ 443** TYPES: PRPtrDiff 444** DESCRIPTION: 445** A type for pointer difference. Variables of this type are suitable 446** for storing a pointer or pointer sutraction. 447************************************************************************/ 448typedef ptrdiff_t PRPtrdiff; 449 450/************************************************************************ 451** TYPES: PRUptrdiff 452** DESCRIPTION: 453** A type for pointer difference. Variables of this type are suitable 454** for storing a pointer or pointer sutraction. 455************************************************************************/ 456typedef unsigned long PRUptrdiff; 457 458/************************************************************************ 459** TYPES: PRBool 460** DESCRIPTION: 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************************************************************************/ 466typedef PRIntn PRBool; 467#define PR_TRUE 1 468#define PR_FALSE 0 469 470/************************************************************************ 471** TYPES: PRPackedBool 472** DESCRIPTION: 473** Use PRPackedBOol within structs where bitfields are not desireable 474** but minimum and consistant overhead matters. 475************************************************************************/ 476typedef PRUint8 PRPackedBool; 477 478/* 479** Status code used by some routines that have a single point of failure or 480** special status return. 481*/ 482typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; 483 484#ifdef MOZ_UNICODE 485/* 486 * EXPERIMENTAL: This type may be removed in a future release. 487 */ 488#ifndef __PRUNICHAR__ 489#define __PRUNICHAR__ 490#if defined(WIN32) || defined(XP_MAC) 491typedef wchar_t PRUnichar; 492#else 493typedef PRUint16 PRUnichar; 494#endif 495#endif 496#endif /* MOZ_UNICODE */ 497 498/* 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. 502** 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.) 508*/ 509typedef long PRWord; 510typedef size_t PRUword; 511 512#if defined(NO_NSPR_10_SUPPORT) 513#else 514/********* ???????????????? FIX ME ??????????????????????????? *****/ 515/********************** Some old definitions until pr=>ds transition is done ***/ 516/********************** Also, we are still using NSPR 1.0. GC ******************/ 517/* 518** Fundamental NSPR macros, used nearly everywhere. 519*/ 520 521#define PR_PUBLIC_API PR_IMPLEMENT 522 523/* 524** Macro body brackets so that macros with compound statement definitions 525** behave syntactically more like functions when called. 526*/ 527#define NSPR_BEGIN_MACRO do { 528#define NSPR_END_MACRO } while (0) 529 530/* 531** Macro shorthands for conditional C++ extern block delimiters. 532*/ 533#ifdef NSPR_BEGIN_EXTERN_C 534#undef NSPR_BEGIN_EXTERN_C 535#endif 536#ifdef NSPR_END_EXTERN_C 537#undef NSPR_END_EXTERN_C 538#endif 539 540#ifdef __cplusplus 541#define NSPR_BEGIN_EXTERN_C extern "C" { 542#define NSPR_END_EXTERN_C } 543#else 544#define NSPR_BEGIN_EXTERN_C 545#define NSPR_END_EXTERN_C 546#endif 547 548#ifdef XP_MAC 549#include "protypes.h" 550#else 551#include "obsolete/protypes.h" 552#endif 553 554/********* ????????????? End Fix me ?????????????????????????????? *****/ 555#endif /* NO_NSPR_10_SUPPORT */ 556 557PR_END_EXTERN_C 558 559#endif /* prtypes_h___ */ 560 561