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.

145 lines
3.7 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. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifndef _INC_STDARG
  18. #define _INC_STDARG
  19. #if !defined(_WIN32)
  20. #error ERROR: Only Win32 target supported!
  21. #endif
  22. #ifdef _MSC_VER
  23. /*
  24. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. * alignment.
  26. */
  27. #pragma pack(push,8)
  28. #endif /* _MSC_VER */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #if !defined(_W64)
  33. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  34. #define _W64 __w64
  35. #else
  36. #define _W64
  37. #endif
  38. #endif
  39. #ifndef _UINTPTR_T_DEFINED
  40. #ifdef _WIN64
  41. typedef unsigned __int64 uintptr_t;
  42. #else
  43. typedef _W64 unsigned int uintptr_t;
  44. #endif
  45. #define _UINTPTR_T_DEFINED
  46. #endif
  47. #ifndef _VA_LIST_DEFINED
  48. typedef char * va_list;
  49. #define _VA_LIST_DEFINED
  50. #endif
  51. #ifdef __cplusplus
  52. #define _ADDRESSOF(v) ( &reinterpret_cast<const char &>(v) )
  53. #else
  54. #define _ADDRESSOF(v) ( &(v) )
  55. #endif
  56. #if defined(_M_CEE)
  57. extern void __cdecl __va_start(va_list*, ...);
  58. extern void * __cdecl __va_arg(va_list*, ...);
  59. extern void __cdecl __va_end(va_list*);
  60. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), sizeof(v), \
  61. __builtin_alignof(v), _ADDRESSOF(v)) )
  62. #define va_arg(ap,t) ( *(t *)__va_arg(&ap, sizeof(t), \
  63. __builtin_alignof(t), (t *)0) )
  64. #define va_end(ap) ( __va_end(&ap) )
  65. #elif defined(_M_IX86)
  66. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  67. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  68. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  69. #define va_end(ap) ( ap = (va_list)0 )
  70. #elif defined(_M_IA64)
  71. #define _VA_STRUCT_ALIGN 16
  72. #define _VA_ALIGN 8
  73. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  74. - (ap))
  75. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  76. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  77. #ifdef __cplusplus
  78. extern void __cdecl __va_start(va_list*, ...);
  79. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), \
  80. _ADDRESSOF(v)) )
  81. #else
  82. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _SLOTSIZEOF(v) )
  83. #endif
  84. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  85. -_SLOTSIZEOF(t)))
  86. #define va_end(ap) ( ap = (va_list)0 )
  87. #elif defined(_M_AMD64)
  88. extern void __cdecl __va_start(va_list *, ...);
  89. #define va_start(ap, x) ( __va_start(&ap, x) )
  90. #define va_arg(ap, t) \
  91. ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
  92. ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
  93. : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
  94. #define va_end(ap) ( ap = (va_list)0 )
  95. #else
  96. /* A guess at the proper definitions for other platforms */
  97. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  98. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  99. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  100. #define va_end(ap) ( ap = (va_list)0 )
  101. #endif
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #ifdef _MSC_VER
  106. #pragma pack(pop)
  107. #endif /* _MSC_VER */
  108. #endif /* _INC_STDARG */