Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.1 KiB

  1. /***
  2. *stdarg.h - defines ANSI-style macros for variable argument functions
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines ANSI-style macros for accessing arguments
  8. * of functions which take a variable number of arguments.
  9. * [ANSI]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 05-03-89 JCR Added _INTERNAL_IFSTRIP for relinc usage
  15. * 08-15-89 GJF Cleanup, now specific to OS/2 2.0 (i.e., 386 flat model)
  16. * 10-30-89 GJF Fixed copyright
  17. * 11-02-89 JCR Changed "DLL" to "_DLL"
  18. * 01-05-90 JCR Added NULL definition
  19. * 03-02-90 GJF Added #ifndef _INC_STDARG stuff. Also, removed some
  20. * (now) useless preprocessor directives.
  21. * 05-29-90 GJF Replaced sizeof() with _INTSIZEOF() and revised the
  22. * va_arg() macro (fixes PTM 60)
  23. * 05-31-90 GJF Revised va_end() macro (propagated 5-25-90 change to
  24. * crt7 version by WAJ)
  25. * 10-30-90 GJF Moved the real definitions into cruntime.h (for NT
  26. * folks) and relinc.sed (to release ANSI compatible
  27. * version). Ugly compromise.
  28. * 08-20-91 JCR C++ and ANSI naming
  29. * 11-01-91 GDP MIPS Compiler support. Moved real definitions back here
  30. * 10-16-92 SKS Replaced "#ifdef i386" with "#ifdef _M_IX86".
  31. * 11-03-92 GJF Fixed several conditionals, dropped _DOSX32_ support.
  32. * 01-03-93 SRW Fold in ALPHA changes
  33. * 01-09-93 SRW Remove usage of MIPS and ALPHA to conform to ANSI
  34. * Use _MIPS_ and _ALPHA_ instead.
  35. * 01-25-93 GJF Fix va_list definition.
  36. * 10-04-93 SRW Fix ifdefs for MIPS and ALPHA to only check for _M_?????? defines
  37. * 10-12-93 GJF Merged NT version into Cuda version. Also, replaced
  38. * _ALPHA_ with _M_ALPHA.
  39. * 11-11-93 GJF Minor cosmetic changes.
  40. * 04-05-94 SKS Add prototype of __builtin_va_start for ALPHA
  41. * 10-02-94 BWT Add PPC support.
  42. * 11-03-94 GJF Ensure 8 byte alignment.
  43. * 12-28-94 JCF Merged with mac header.
  44. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  45. * 02-14-95 CFW Clean up Mac merge.
  46. * 12-14-95 JWM Add "#pragma once".
  47. * 02-24-97 GJF Detab-ed.
  48. * 10-07-97 RDL Added IA64.
  49. * 11-07-97 RDL Soft23 definitions.
  50. * 02-06-98 GJF Changes for Win64: fixed _APALIGN() macro (fix from
  51. * Intel)
  52. * 05-17-99 PML Remove all Macintosh support.
  53. * 10-06-99 PML Add _W64 modifier to types which are 32 bits in Win32,
  54. * 64 bits in Win64.
  55. * 10-25-99 PML Add support for _M_CEE (VS7#54572).
  56. * 01-20-00 PML Remove __epcg__.
  57. * 05-17-00 PML Use __alignof in _APALIGN macro for IA64.
  58. * 09-07-00 PML Remove va_list definition for _M_CEE (vs7#159777)
  59. * 09-21-00 PML Change IA64 definition of va_start for C++ (vs7#103357)
  60. * 02-05-01 PML Fix va_start for classes with operator& (vs7#201535)
  61. * 03-19-01 BWT Add AMD64 changes
  62. * 03-26-01 GB Added va_args for AMD64
  63. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  64. *
  65. ****/
  66. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  67. #pragma once
  68. #endif
  69. #ifndef _INC_STDARG
  70. #define _INC_STDARG
  71. #if !defined(_WIN32)
  72. #error ERROR: Only Win32 target supported!
  73. #endif
  74. #ifndef _CRTBLD
  75. /* This version of the header files is NOT for user programs.
  76. * It is intended for use when building the C runtimes ONLY.
  77. * The version intended for public use will not have this message.
  78. */
  79. #error ERROR: Use of C runtime library internal header file.
  80. #endif /* _CRTBLD */
  81. #ifdef _MSC_VER
  82. /*
  83. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  84. * alignment.
  85. */
  86. #pragma pack(push,8)
  87. #endif /* _MSC_VER */
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. #ifndef _INTERNAL_IFSTRIP_
  92. #include <cruntime.h>
  93. #endif /* _INTERNAL_IFSTRIP_ */
  94. #if !defined(_W64)
  95. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 /*IFSTRIP=IGN*/
  96. #define _W64 __w64
  97. #else
  98. #define _W64
  99. #endif
  100. #endif
  101. #ifndef _UINTPTR_T_DEFINED
  102. #ifdef _WIN64
  103. typedef unsigned __int64 uintptr_t;
  104. #else
  105. typedef _W64 unsigned int uintptr_t;
  106. #endif
  107. #define _UINTPTR_T_DEFINED
  108. #endif
  109. #ifndef _VA_LIST_DEFINED
  110. typedef char * va_list;
  111. #define _VA_LIST_DEFINED
  112. #endif
  113. #ifdef __cplusplus
  114. #define _ADDRESSOF(v) ( &reinterpret_cast<const char &>(v) )
  115. #else
  116. #define _ADDRESSOF(v) ( &(v) )
  117. #endif
  118. #if defined(_M_CEE)
  119. extern void __cdecl __va_start(va_list*, ...);
  120. extern void * __cdecl __va_arg(va_list*, ...);
  121. extern void __cdecl __va_end(va_list*);
  122. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), sizeof(v), \
  123. __builtin_alignof(v), _ADDRESSOF(v)) )
  124. #define va_arg(ap,t) ( *(t *)__va_arg(&ap, sizeof(t), \
  125. __builtin_alignof(t), (t *)0) )
  126. #define va_end(ap) ( __va_end(&ap) )
  127. #elif defined(_M_IX86)
  128. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  129. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  130. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  131. #define va_end(ap) ( ap = (va_list)0 )
  132. #elif defined(_M_IA64)
  133. #define _VA_STRUCT_ALIGN 16
  134. #define _VA_ALIGN 8
  135. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  136. - (ap))
  137. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  138. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  139. #ifdef __cplusplus
  140. extern void __cdecl __va_start(va_list*, ...);
  141. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), \
  142. _ADDRESSOF(v)) )
  143. #else
  144. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _SLOTSIZEOF(v) )
  145. #endif
  146. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  147. -_SLOTSIZEOF(t)))
  148. #define va_end(ap) ( ap = (va_list)0 )
  149. #elif defined(_M_AMD64)
  150. extern void __cdecl __va_start(va_list *, ...);
  151. #define va_start(ap, x) ( __va_start(&ap, x) )
  152. #define va_arg(ap, t) \
  153. ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
  154. ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
  155. : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
  156. #define va_end(ap) ( ap = (va_list)0 )
  157. #else
  158. /* A guess at the proper definitions for other platforms */
  159. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  160. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  161. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  162. #define va_end(ap) ( ap = (va_list)0 )
  163. #endif
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #ifdef _MSC_VER
  168. #pragma pack(pop)
  169. #endif /* _MSC_VER */
  170. #endif /* _INC_STDARG */