migrate substitution keywords to SVN
[reactos.git] / reactos / include / msvcrt / stdarg.h
1 /*
2 * stdarg.h
3 *
4 * Provides facilities for stepping through a list of function arguments of
5 * an unknown number and type.
6 *
7 * NOTE: Gcc should provide stdarg.h, and I believe their version will work
8 * with crtdll. If necessary I think you can replace this with the GCC
9 * stdarg.h (or is it vararg.h).
10 *
11 * Note that the type used in va_arg is supposed to match the actual type
12 * *after default promotions*. Thus, va_arg (..., short) is not valid.
13 *
14 * This file is part of the Mingw32 package.
15 *
16 * Contributors:
17 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
18 *
19 * THIS SOFTWARE IS NOT COPYRIGHTED
20 *
21 * This source code is offered for use in the public domain. You may
22 * use, modify or distribute it freely.
23 *
24 * This code is distributed in the hope that it will be useful but
25 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
26 * DISCLAIMED. This includes but is not limited to warranties of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 *
29 * $Revision: 1.5 $
30 * $Author$
31 * $Date$
32 *
33 */
34 /* Appropriated for Reactos Crtdll by Ariadne */
35
36 #ifndef _STDARG_H_
37 #define _STDARG_H_
38
39 /*
40 * Don't do any of this stuff for the resource compiler.
41 */
42 #ifndef RC_INVOKED
43
44 /*
45 * I was told that Win NT likes this.
46 */
47 #ifndef _VA_LIST_DEFINED
48 #define _VA_LIST_DEFINED
49 #endif
50
51 #ifndef _VA_LIST
52 #define _VA_LIST
53 typedef char* va_list;
54 #endif
55
56
57 /*
58 * Amount of space required in an argument list (ie. the stack) for an
59 * argument of type t.
60 */
61 #define __va_argsiz(t) \
62 (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
63
64
65 /*
66 * Start variable argument list processing by setting AP to point to the
67 * argument after pN.
68 */
69 #ifdef __GNUC__
70 /*
71 * In GNU the stack is not necessarily arranged very neatly in order to
72 * pack shorts and such into a smaller argument list. Fortunately a
73 * neatly arranged version is available through the use of __builtin_next_arg.
74 */
75 #ifndef va_start
76 #define va_start(ap, pN) \
77 ((ap) = ((va_list) __builtin_next_arg(pN)))
78 #endif
79 #else
80 /*
81 * For a simple minded compiler this should work (it works in GNU too for
82 * vararg lists that don't follow shorts and such).
83 */
84 #ifndef va_start
85 #define va_start(ap, pN) \
86 ((ap) = ((va_list) (&pN) + __va_argsiz(pN)))
87 #endif
88 #endif
89
90
91 /*
92 * End processing of variable argument list. In this case we do nothing.
93 */
94 #ifndef va_end
95 #define va_end(ap) ((void)0)
96 #endif
97
98
99 /*
100 * Increment ap to the next argument in the list while returing a
101 * pointer to what ap pointed to first, which is of type t.
102 *
103 * We cast to void* and then to t* because this avoids a warning about
104 * increasing the alignment requirement.
105 */
106
107 #ifndef va_arg
108 #define va_arg(ap, t) \
109 (((ap) = (ap) + __va_argsiz(t)), \
110 *((t*) (void*) ((ap) - __va_argsiz(t))))
111 #endif
112
113 #endif /* Not RC_INVOKED */
114
115 #endif /* not _STDARG_H_ */