]> git.sur5r.net Git - openldap/blob - build/unproto/stdarg.h
Initial revision
[openldap] / build / unproto / stdarg.h
1  /*
2   * @(#) stdarg.h 1.4 93/06/18 22:29:44
3   * 
4   * Sample stdarg.h file for use with the unproto filter.
5   * 
6   * This file serves two purposes.
7   * 
8   * 1 - On systems that do not have a /usr/include/stdarg.h file, it should be
9   * included by C source files that implement ANSI-style variadic functions.
10   * Ultrix 4.[0-2] comes with stdarg.h but still needs the one that is
11   * provided with the unproto filter.
12   * 
13   * 2 - To configure the unprototyper itself. If the _VA_ALIST_ macro is
14   * defined, its value will appear in the place of the "..." at the end of
15   * argument lists of variadic function *definitions* (not declarations).
16   * Some compilers (such as Greenhills m88k) have a non-empty va_dcl
17   * definition in the system header file varargs.h. If that is the case,
18   * define "_VA_DCL_" with the same value as va_dcl. If _VA_DCL_ is defined,
19   * the unprototyper will emit its value just before the opening "{".
20   * 
21   * Compilers that always pass arguments via the stack can use the default code
22   * at the end of this file (this usually applies for the vax, mc68k and
23   * 80*86 architectures).
24   * 
25   * Special tricks are needed for compilers that pass some or all function
26   * arguments via registers. Examples of the latter are given for the mips
27   * and sparc architectures. Usually the compiler special-cases an argument
28   * declaration such as "va_alist" or "__builtin_va_alist". For inspiration,
29   * see the local /usr/include/varargs.h file.
30   * 
31   * You can use the varargs.c program provided with the unproto package to
32   * verify that the stdarg.h file has been set up correctly.
33   */
34
35 #ifdef sparc /* tested with SunOS 4.1.1 */
36
37 #define _VA_ALIST_              "__builtin_va_alist"
38 typedef char *va_list;
39 #define va_start(ap, p)         (ap = (char *) &__builtin_va_alist)
40 #define va_arg(ap, type)        ((type *) __builtin_va_arg_incr((type *) ap))[0]
41 #define va_end(ap)
42
43 #else
44 #ifdef mips /* tested with Ultrix 4.0 and 4.2 */
45
46 #define _VA_ALIST_              "va_alist"
47 #include "/usr/include/stdarg.h"
48
49 #else
50 #ifdef m88k /* Motorola SYSTEM V/88 R32V3 */
51
52 #define _VA_ALIST_              "va_alist"
53 #define _VA_DCL_                "va_type va_alist;"
54 typedef struct _va_struct {
55     int va_narg;
56     int *va_stkaddr;
57     int *va_iregs;
58 } va_list;
59 #define va_start(ap, p) \
60 ((ap).va_narg=(int *)&va_alist-va_stkarg, \
61  (ap).va_stkaddr=va_stkarg, \
62  (ap).va_iregs=(int *)va_intreg)
63 #define va_end(p)
64 #if defined(LittleEndian)
65 #define va_arg(p,mode) \
66     (*(mode *)_gh_va_arg(&p, va_align(mode), va_regtyp(mode), sizeof(mode)))
67 #else /* defined(LittleEndian) */
68 #define va_arg(p,mode) ( \
69     (p).va_narg += ((p).va_narg & (va_align(mode) == 8)) + \
70                       (sizeof(mode)+3)/4, \
71     ((mode *)((va_regtyp(mode) && (p).va_narg <= 8 ? \
72              (p).va_iregs: \
73              (p).va_stkaddr) + (p).va_narg))[-1])
74 #endif /* defined(LittleEndian) */
75
76 #else
77 #ifdef hpux
78 #include <stdarg.h>
79
80 #else /* vax, mc68k, 80*86 */
81
82 typedef char *va_list;
83 #define va_start(ap, p)         (ap = (char *) (&(p)+1))
84 #define va_arg(ap, type)        ((type *) (ap += sizeof(type)))[-1]
85 #define va_end(ap)
86
87 #endif /* hpux */
88 #endif /* m88k */
89 #endif /* mips */
90 #endif /* sparc */