Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / include / vadefs.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)vadefs.h 1.5 01/07/15 Copyright 1998 J. Schilling */
14 /*
15  *      Generic header for users of var args ...
16  *
17  *      Includes a default definition for va_copy()
18  *      and some magic know how about the SVr4 Power PC var args ABI
19  *      to create a __va_arg_list() macro.
20  *
21  *      Copyright (c) 1998 J. Schilling
22  */
23 /*
24  * This program is free software; you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License version 2
26  * as published by the Free Software Foundation.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License along with
34  * this program; see the file COPYING.  If not, write to the Free Software
35  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36  */
37
38 #ifndef _VADEFS_H
39 #define _VADEFS_H
40
41 #ifndef _MCONFIG_H
42 #include <mconfig.h>
43 #endif
44
45 #ifdef  PROTOTYPES
46 /*
47  * For ANSI C-compilers prefer stdarg.h
48  */
49 #       ifdef   HAVE_STDARG_H
50 #               ifndef  _INCL_STDARG_H
51 #               include <stdarg.h>
52 #               define  _INCL_STDARG_H
53 #               endif
54 #       else
55 #               ifndef  _INCL_VARARGS_H
56 #               include <varargs.h>
57 #               define  _INCL_VARARGS_H
58 #               endif
59 #       endif
60 #else
61 /*
62  * For K&R C-compilers prefer varargs.h
63  */
64 #       ifdef   HAVE_VARARGS_H
65 #               ifndef  _INCL_VARARGS_H
66 #               include <varargs.h>
67 #               define  _INCL_VARARGS_H
68 #               endif
69 #       else
70 #               ifndef  _INCL_STDARG_H
71 #               include <stdarg.h>
72 #               define  _INCL_STDARG_H
73 #               endif
74 #       endif
75 #endif
76
77 #if (defined(__linux__) || defined(__linux) || defined(sun)) && \
78                 (defined(__ppc) || defined(__PPC) || defined(powerpc) || defined(__powerpc__))
79
80 #       ifndef  VA_LIST_IS_ARRAY
81 #       define  VA_LIST_IS_ARRAY
82 #       endif
83 #endif
84
85
86 /*
87  * __va_copy() is used by GCC 2.8 or newer until va_copy() becomes
88  * a final ISO standard.
89  */
90 #if !defined(va_copy) && !defined(HAVE_VA_COPY)
91 #       if      defined(__va_copy)
92 #               define  va_copy(to, from)       __va_copy(to, from)
93 #       endif
94 #endif
95
96 /*
97  * va_copy() is a Solaris extension to provide a portable way to perform a
98  * variable argument list "bookmarking" function.
99  * If it is not available via stdarg.h, use a simple assignement for backward
100  * compatibility.
101  */
102 #if !defined(va_copy) && !defined(HAVE_VA_COPY)
103 #ifdef  VA_LIST_IS_ARRAY
104 #       define  va_copy(to, from)       ((to)[0] = (from)[0])
105 #else
106 #       define  va_copy(to, from)       ((to) = (from))
107 #endif
108 #endif
109
110 /*
111  * I don't know any portable way to get an arbitrary
112  * C object from a var arg list so I use a
113  * system-specific routine __va_arg_list() that knows
114  * if 'va_list' is an array. You will not be able to
115  * assign the value of __va_arg_list() but it works
116  * to be used as an argument of a function.
117  * It is a requirement for recursive printf to be able
118  * to use this function argument. If your system
119  * defines va_list to be an array you need to know this
120  * via autoconf or another mechanism.
121  * It would be nice to have something like
122  * __va_arg_list() in stdarg.h
123  */
124
125 #ifdef  VA_LIST_IS_ARRAY
126 #       define  __va_arg_list(list)     va_arg(list, void *)
127 #else
128 #       define  __va_arg_list(list)     va_arg(list, va_list)
129 #endif
130
131 #endif  /* _VADEFS_H */