home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prtypes.h < prev    next >
C/C++ Source or Header  |  1998-11-21  |  14KB  |  396 lines

  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 Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. ** File:                prtypes.h
  21. ** Description: Definitions of NSPR's basic types
  22. **
  23. ** Prototypes and macros used to make up for deficiencies in ANSI environments
  24. ** that we have found.
  25. **
  26. ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
  27. ** of portable code will not know in general that they need these definitions.
  28. ** Instead of requiring these authors to find the dependent uses in their code
  29. ** and take the following steps only in those C files, we take steps once here
  30. ** for all C files.
  31. **/
  32.  
  33. #ifndef prtypes_h___
  34. #define prtypes_h___
  35.  
  36. #include "prcpucfg.h"
  37.  
  38. #include <stddef.h>
  39.  
  40. /***********************************************************************
  41. ** MACROS:      PR_EXTERN
  42. **              PR_IMPLEMENT
  43. ** DESCRIPTION:
  44. **      These are only for externally visible routines and globals.  For
  45. **      internal routines, just use "extern" for type checking and that
  46. **      will not export internal cross-file or forward-declared symbols.
  47. **      Define a macro for declaring procedures return types. We use this to
  48. **      deal with windoze specific type hackery for DLL definitions. Use
  49. **      PR_EXTERN when the prototype for the method is declared. Use
  50. **      PR_IMPLEMENT for the implementation of the method.
  51. **
  52. ** Example:
  53. **   in dowhim.h
  54. **     PR_EXTERN( void ) DoWhatIMean( void );
  55. **   in dowhim.c
  56. **     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
  57. **
  58. **
  59. ***********************************************************************/
  60. #if defined(WIN32)
  61. #define PR_EXTERN(__type) extern _declspec(dllexport) __type
  62. #define PR_IMPLEMENT(__type) _declspec(dllexport) __type
  63. #define PR_EXTERN_DATA(__type) extern _declspec(dllexport) __type
  64. #define PR_IMPLEMENT_DATA(__type) _declspec(dllexport) __type
  65.  
  66. #define PR_CALLBACK
  67. #define PR_CALLBACK_DECL
  68. #define PR_STATIC_CALLBACK(__x) static __x
  69.  
  70. #elif defined(WIN16)
  71.  
  72. #define PR_CALLBACK_DECL        __cdecl
  73.  
  74. #if defined(_WINDLL)
  75. #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
  76. #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
  77. #define PR_EXTERN_DATA(__type) extern __type _export
  78. #define PR_IMPLEMENT_DATA(__type) __type _export
  79.  
  80. #define PR_CALLBACK             __cdecl __loadds
  81. #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
  82.  
  83. #else /* this must be .EXE */
  84. #define PR_EXTERN(__type) extern __type _cdecl _export
  85. #define PR_IMPLEMENT(__type) __type _cdecl _export
  86. #define PR_EXTERN_DATA(__type) extern __type _export
  87. #define PR_IMPLEMENT_DATA(__type) __type _export
  88.  
  89. #define PR_CALLBACK             __cdecl __loadds
  90. #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
  91. #endif /* _WINDLL */
  92.  
  93. #elif defined(XP_MAC)
  94. #define PR_EXTERN(__type) extern __declspec(export) __type
  95. #define PR_IMPLEMENT(__type) __declspec(export) __type
  96. #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
  97. #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
  98.  
  99. #define PR_CALLBACK
  100. #define PR_CALLBACK_DECL
  101. #define PR_STATIC_CALLBACK(__x) static __x
  102.  
  103. #elif defined(XP_OS2) 
  104. #define PR_EXTERN(__type) extern __type
  105. #define PR_IMPLEMENT(__type) __type
  106. #define PR_EXTERN_DATA(__type) extern __type
  107. #define PR_IMPLEMENT_DATA(__type) __type
  108. #define PR_CALLBACK
  109. #define PR_CALLBACK_DECL
  110. #ifndef XP_OS2_VACPP
  111. #define PR_STATIC_CALLBACK(__x) static __x
  112. #else
  113. #define PR_STATIC_CALLBACK(__x) static __x _Optlink
  114. #endif
  115.  
  116. #else /* Unix */
  117. #define PR_EXTERN(__type) extern __type
  118. #define PR_IMPLEMENT(__type) __type
  119. #define PR_EXTERN_DATA(__type) extern __type
  120. #define PR_IMPLEMENT_DATA(__type) __type
  121. #define PR_CALLBACK
  122. #define PR_CALLBACK_DECL
  123. #define PR_STATIC_CALLBACK(__x) static __x
  124.  
  125. #endif
  126.  
  127. /***********************************************************************
  128. ** MACROS:      PR_BEGIN_MACRO
  129. **              PR_END_MACRO
  130. ** DESCRIPTION:
  131. **      Macro body brackets so that macros with compound statement definitions
  132. **      behave syntactically more like functions when called.
  133. ***********************************************************************/
  134. #define PR_BEGIN_MACRO  do {
  135. #define PR_END_MACRO    } while (0)
  136.  
  137. /***********************************************************************
  138. ** MACROS:      PR_BEGIN_EXTERN_C
  139. **              PR_END_EXTERN_C
  140. ** DESCRIPTION:
  141. **      Macro shorthands for conditional C++ extern block delimiters.
  142. ***********************************************************************/
  143. #ifdef __cplusplus
  144. #define PR_BEGIN_EXTERN_C       extern "C" {
  145. #define PR_END_EXTERN_C         }
  146. #else
  147. #define PR_BEGIN_EXTERN_C
  148. #define PR_END_EXTERN_C
  149. #endif
  150.  
  151. /***********************************************************************
  152. ** MACROS:      PR_BIT
  153. **              PR_BITMASK
  154. ** DESCRIPTION:
  155. ** Bit masking macros.  XXX n must be <= 31 to be portable
  156. ***********************************************************************/
  157. #define PR_BIT(n)       ((PRUint32)1 << (n))
  158. #define PR_BITMASK(n)   (PR_BIT(n) - 1)
  159.  
  160. /***********************************************************************
  161. ** MACROS:      PR_ROUNDUP
  162. **              PR_MIN
  163. **                              PR_MAX
  164. ** DESCRIPTION:
  165. **      Commonly used macros for operations on compatible types.
  166. ***********************************************************************/
  167. #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
  168. #define PR_MIN(x,y)     ((x)<(y)?(x):(y))
  169. #define PR_MAX(x,y)     ((x)>(y)?(x):(y))
  170.  
  171. PR_BEGIN_EXTERN_C
  172.  
  173. /************************************************************************
  174. ** TYPES:       PRUint8
  175. **              PRInt8
  176. ** DESCRIPTION:
  177. **  The int8 types are known to be 8 bits each. There is no type that
  178. **      is equivalent to a plain "char". 
  179. ************************************************************************/
  180. #if PR_BYTES_PER_BYTE == 1
  181. typedef unsigned char PRUint8;
  182. /*
  183. ** Some cfront-based C++ compilers do not like 'signed char' and
  184. ** issue the warning message:
  185. **     warning: "signed" not implemented (ignored)
  186. ** For these compilers, we have to define PRInt8 as plain 'char'.
  187. ** Make sure that plain 'char' is indeed signed under these compilers.
  188. */
  189. #if (defined(HPUX) && defined(__cplusplus) \
  190.         && !defined(__GNUC__) && __cplusplus < 199707L) \
  191.     || (defined(SCO) && defined(__cplusplus) \
  192.         && !defined(__GNUC__) && __cplusplus == 1L)
  193. typedef char PRInt8;
  194. #else
  195. typedef signed char PRInt8;
  196. #endif
  197. #else
  198. #error No suitable type for PRInt8/PRUint8
  199. #endif
  200.  
  201. /************************************************************************
  202. ** TYPES:       PRUint16
  203. **              PRInt16
  204. ** DESCRIPTION:
  205. **  The int16 types are known to be 16 bits each. 
  206. ************************************************************************/
  207. #if PR_BYTES_PER_SHORT == 2
  208. typedef unsigned short PRUint16;
  209. typedef short PRInt16;
  210. #else
  211. #error No suitable type for PRInt16/PRUint16
  212. #endif
  213.  
  214. /************************************************************************
  215. ** TYPES:       PRUint32
  216. **              PRInt32
  217. ** DESCRIPTION:
  218. **  The int32 types are known to be 32 bits each. 
  219. ************************************************************************/
  220. #if PR_BYTES_PER_INT == 4
  221. typedef unsigned int PRUint32;
  222. typedef int PRInt32;
  223. #define PR_INT32(x)  x
  224. #define PR_UINT32(x) x ## U
  225. #elif PR_BYTES_PER_LONG == 4
  226. typedef unsigned long PRUint32;
  227. typedef long PRInt32;
  228. #define PR_INT32(x)  x ## L
  229. #define PR_UINT32(x) x ## UL
  230. #else
  231. #error No suitable type for PRInt32/PRUint32
  232. #endif
  233.  
  234. /************************************************************************
  235. ** TYPES:       PRUint64
  236. **              PRInt64
  237. ** DESCRIPTION:
  238. **  The int64 types are known to be 64 bits each. Care must be used when
  239. **      declaring variables of type PRUint64 or PRInt64. Different hardware
  240. **      architectures and even different compilers have varying support for
  241. **      64 bit values. The only guaranteed portability requires the use of
  242. **      the LL_ macros (see prlong.h).
  243. ************************************************************************/
  244. #ifdef HAVE_LONG_LONG
  245. #if PR_BYTES_PER_LONG == 8
  246. typedef long PRInt64;
  247. typedef unsigned long PRUint64;
  248. #elif defined(WIN16)
  249. typedef __int64 PRInt64;
  250. typedef unsigned __int64 PRUint64;
  251. #elif defined(WIN32)
  252. typedef __int64  PRInt64;
  253. typedef unsigned __int64 PRUint64;
  254. #else
  255. typedef long long PRInt64;
  256. typedef unsigned long long PRUint64;
  257. #endif /* PR_BYTES_PER_LONG == 8 */
  258. #else  /* !HAVE_LONG_LONG */
  259. typedef struct {
  260. #ifdef IS_LITTLE_ENDIAN
  261.     PRUint32 lo, hi;
  262. #else
  263.     PRUint32 hi, lo;
  264. #endif
  265. } PRInt64;
  266. typedef PRInt64 PRUint64;
  267. #endif /* !HAVE_LONG_LONG */
  268.  
  269. /************************************************************************
  270. ** TYPES:       PRUintn
  271. **              PRIntn
  272. ** DESCRIPTION:
  273. **  The PRIntn types are most appropriate for automatic variables. They are
  274. **      guaranteed to be at least 16 bits, though various architectures may
  275. **      define them to be wider (e.g., 32 or even 64 bits). These types are
  276. **      never valid for fields of a structure. 
  277. ************************************************************************/
  278. #if PR_BYTES_PER_INT >= 2
  279. typedef int PRIntn;
  280. typedef unsigned int PRUintn;
  281. #else
  282. #error 'sizeof(int)' not sufficient for platform use
  283. #endif
  284.  
  285. /************************************************************************
  286. ** TYPES:       PRFloat64
  287. ** DESCRIPTION:
  288. **  NSPR's floating point type is always 64 bits. 
  289. ************************************************************************/
  290. typedef double          PRFloat64;
  291.  
  292. /************************************************************************
  293. ** TYPES:       PRSize
  294. ** DESCRIPTION:
  295. **  A type for representing the size of objects. 
  296. ************************************************************************/
  297. typedef size_t PRSize;
  298.  
  299. /************************************************************************
  300. ** TYPES:       PRPtrDiff
  301. ** DESCRIPTION:
  302. **  A type for pointer difference. Variables of this type are suitable
  303. **      for storing a pointer or pointer sutraction. 
  304. ************************************************************************/
  305. typedef ptrdiff_t PRPtrdiff;
  306.  
  307. /************************************************************************
  308. ** TYPES:       PRUptrdiff
  309. ** DESCRIPTION:
  310. **  A type for pointer difference. Variables of this type are suitable
  311. **      for storing a pointer or pointer sutraction. 
  312. ************************************************************************/
  313. typedef unsigned long PRUptrdiff;
  314.  
  315. /************************************************************************
  316. ** TYPES:       PRBool
  317. ** DESCRIPTION:
  318. **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
  319. **      for clarity of target type in assignments and actual arguments. Use
  320. **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
  321. **      juast as you would C int-valued conditions. 
  322. ************************************************************************/
  323. typedef PRIntn PRBool;
  324. #define PR_TRUE (PRIntn)1
  325. #define PR_FALSE (PRIntn)0
  326.  
  327. /************************************************************************
  328. ** TYPES:       PRPackedBool
  329. ** DESCRIPTION:
  330. **  Use PRPackedBOol within structs where bitfields are not desireable
  331. **      but minimum and consistant overhead matters.
  332. ************************************************************************/
  333. typedef PRUint8 PRPackedBool;
  334.  
  335. /*
  336. ** Status code used by some routines that have a single point of failure or 
  337. ** special status return.
  338. */
  339. typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
  340.  
  341. #if defined(NO_NSPR_10_SUPPORT)
  342. #else
  343. /********* ???????????????? FIX ME       ??????????????????????????? *****/
  344. /********************** Some old definitions until pr=>ds transition is done ***/
  345. /********************** Also, we are still using NSPR 1.0. GC ******************/
  346. /*
  347. ** Fundamental NSPR macros, used nearly everywhere.
  348. */
  349.  
  350. #define PR_PUBLIC_API        PR_IMPLEMENT
  351.  
  352. /*
  353. ** Macro body brackets so that macros with compound statement definitions
  354. ** behave syntactically more like functions when called.
  355. */
  356. #define NSPR_BEGIN_MACRO        do {
  357. #define NSPR_END_MACRO          } while (0)
  358.  
  359. /*
  360. ** Macro shorthands for conditional C++ extern block delimiters.
  361. */
  362. #ifdef NSPR_BEGIN_EXTERN_C
  363. #undef NSPR_BEGIN_EXTERN_C
  364. #endif
  365. #ifdef NSPR_END_EXTERN_C
  366. #undef NSPR_END_EXTERN_C
  367. #endif
  368.  
  369. #ifdef __cplusplus
  370. #define NSPR_BEGIN_EXTERN_C     extern "C" {
  371. #define NSPR_END_EXTERN_C       }
  372. #else
  373. #define NSPR_BEGIN_EXTERN_C
  374. #define NSPR_END_EXTERN_C
  375. #endif
  376.  
  377. /*
  378. ** A PRWord is an integer that is the same size as a void*
  379. */
  380. typedef long PRWord;
  381. typedef unsigned long PRUword;
  382.  
  383. /********* ????????????? End Fix me ?????????????????????????????? *****/
  384. #endif /* NO_NSPR_10_SUPPORT */
  385.  
  386. #ifdef XP_MAC
  387. #include "protypes.h"
  388. #else
  389. #include "obsolete/protypes.h"
  390. #endif
  391.  
  392. PR_END_EXTERN_C
  393.  
  394. #endif /* prtypes_h___ */
  395.  
  396.