varargs.h revision 104584
11543Srgrimes/*-
296317Sobrien * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
31543Srgrimes * Copyright (c) 1990, 1993
41543Srgrimes *	The Regents of the University of California.  All rights reserved.
51543Srgrimes * (c) UNIX System Laboratories, Inc.
61543Srgrimes * All or some portions of this file are derived from material licensed
71543Srgrimes * to the University of California by American Telephone and Telegraph
81543Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
91543Srgrimes * the permission of UNIX System Laboratories, Inc.
101543Srgrimes *
111543Srgrimes * Redistribution and use in source and binary forms, with or without
121543Srgrimes * modification, are permitted provided that the following conditions
131543Srgrimes * are met:
141543Srgrimes * 1. Redistributions of source code must retain the above copyright
151543Srgrimes *    notice, this list of conditions and the following disclaimer.
161543Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
171543Srgrimes *    notice, this list of conditions and the following disclaimer in the
181543Srgrimes *    documentation and/or other materials provided with the distribution.
191543Srgrimes * 3. All advertising materials mentioning features or use of this software
201543Srgrimes *    must display the following acknowledgement:
211543Srgrimes *	This product includes software developed by the University of
221543Srgrimes *	California, Berkeley and its contributors.
231543Srgrimes * 4. Neither the name of the University nor the names of its contributors
241543Srgrimes *    may be used to endorse or promote products derived from this software
251543Srgrimes *    without specific prior written permission.
261543Srgrimes *
271543Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
281543Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
291543Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
301543Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
311543Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321543Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331543Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341543Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
351543Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
361543Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
371543Srgrimes * SUCH DAMAGE.
381543Srgrimes *
391543Srgrimes *	@(#)varargs.h	8.2 (Berkeley) 3/22/94
4050477Speter * $FreeBSD: head/sys/i386/include/varargs.h 104584 2002-10-06 22:02:06Z mike $
411543Srgrimes */
421543Srgrimes
431543Srgrimes#ifndef _VARARGS_H_
441543Srgrimes#define	_VARARGS_H_
451543Srgrimes
4696317Sobrien#if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3)
4796317Sobrien
48102227Smike#include <sys/_types.h>
4996317Sobrien
50104584Smike#ifndef _VA_LIST_DECLARED
51104584Smike#define	_VA_LIST_DECLARED
52102227Smiketypedef	__va_list	va_list;
53104584Smike#endif
54104584Smike
5596317Sobrientypedef int __builtin_va_alist_t __attribute__((__mode__(__word__)));
5696317Sobrien
5796317Sobrien#define	va_alist		__builtin_va_alist
5896317Sobrien#define	va_dcl			__builtin_va_alist_t __builtin_va_alist; ...
5996317Sobrien#define	va_start(ap)		__builtin_varargs_start(ap)
6096317Sobrien#define	va_arg(ap, type)	__builtin_va_arg((ap), type)
6196317Sobrien#define	va_end(ap)		__builtin_va_end(ap)
6296317Sobrien
6396317Sobrien#else	/* ! __GNUC__ post GCC 2.95 */
6496317Sobrien
651543Srgrimestypedef char *va_list;
661543Srgrimes
6726771Sbde#define	__va_size(type) \
6826771Sbde	(((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
6926771Sbde
7022415Sphk#ifdef __GNUC__
7123184Sbde#define	va_alist	__builtin_va_alist
7223184Sbde#endif
7323184Sbde#if __GNUC__ > 1
7422415Sphk#define	va_dcl	int va_alist; ...
7523184Sbde#else
7622415Sphk#define	va_dcl	int va_alist;
7722415Sphk#endif
781543Srgrimes
791543Srgrimes#define	va_start(ap) \
8026771Sbde	((ap) = (va_list)&va_alist)
811543Srgrimes
821543Srgrimes#define	va_arg(ap, type) \
8326771Sbde	(*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
841543Srgrimes
851543Srgrimes#define	va_end(ap)
861543Srgrimes
8796317Sobrien#endif /* __GNUC__ post GCC 2.95 */
8896317Sobrien
891543Srgrimes#endif /* !_VARARGS_H_ */
90