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 * 4. Neither the name of the University nor the names of its contributors
201543Srgrimes *    may be used to endorse or promote products derived from this software
211543Srgrimes *    without specific prior written permission.
221543Srgrimes *
231543Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241543Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251543Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261543Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271543Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281543Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291543Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301543Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311543Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321543Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331543Srgrimes * SUCH DAMAGE.
341543Srgrimes *
351543Srgrimes *	@(#)varargs.h	8.2 (Berkeley) 3/22/94
3650477Speter * $FreeBSD$
371543Srgrimes */
381543Srgrimes
39119628Skan#ifndef _MACHINE_VARARGS_H_
40119628Skan#define	_MACHINE_VARARGS_H_
411543Srgrimes
42143063Sjoerg#ifndef _SYS_CDEFS_H_
43143063Sjoerg#error this file needs sys/cdefs.h as a prerequisite
44143063Sjoerg#endif
4596317Sobrien
46143063Sjoerg#ifdef __GNUCLIKE_BUILTIN_VARARGS
47143063Sjoerg
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
63143063Sjoerg#else	/* !__GNUCLIKE_BUILTIN_VARARGS */
6496317Sobrien
651543Srgrimestypedef char *va_list;
661543Srgrimes
6726771Sbde#define	__va_size(type) \
6826771Sbde	(((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
6926771Sbde
70143063Sjoerg#if defined(__GNUCLIKE_BUILTIN_VAALIST)
7123184Sbde#define	va_alist	__builtin_va_alist
7223184Sbde#endif
73143063Sjoerg#ifdef __CC_SUPPORTS_VARADIC_XXX
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
87143063Sjoerg#endif /* __GNUCLIKE_BUILTIN_VARARGS */
8896317Sobrien
89119628Skan#endif /* !_MACHINE_VARARGS_H_ */
90