varargs.h revision 102227
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 102227 2002-08-21 16:20:02Z 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
50102227Smiketypedef	__va_list	va_list;
5196317Sobrientypedef int __builtin_va_alist_t __attribute__((__mode__(__word__)));
5296317Sobrien
5396317Sobrien#define	va_alist		__builtin_va_alist
5496317Sobrien#define	va_dcl			__builtin_va_alist_t __builtin_va_alist; ...
5596317Sobrien#define	va_start(ap)		__builtin_varargs_start(ap)
5696317Sobrien#define	va_arg(ap, type)	__builtin_va_arg((ap), type)
5796317Sobrien#define	va_end(ap)		__builtin_va_end(ap)
5896317Sobrien
5996317Sobrien#else	/* ! __GNUC__ post GCC 2.95 */
6096317Sobrien
611543Srgrimestypedef char *va_list;
621543Srgrimes
6326771Sbde#define	__va_size(type) \
6426771Sbde	(((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
6526771Sbde
6622415Sphk#ifdef __GNUC__
6723184Sbde#define	va_alist	__builtin_va_alist
6823184Sbde#endif
6923184Sbde#if __GNUC__ > 1
7022415Sphk#define	va_dcl	int va_alist; ...
7123184Sbde#else
7222415Sphk#define	va_dcl	int va_alist;
7322415Sphk#endif
741543Srgrimes
751543Srgrimes#define	va_start(ap) \
7626771Sbde	((ap) = (va_list)&va_alist)
771543Srgrimes
781543Srgrimes#define	va_arg(ap, type) \
7926771Sbde	(*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
801543Srgrimes
811543Srgrimes#define	va_end(ap)
821543Srgrimes
8396317Sobrien#endif /* __GNUC__ post GCC 2.95 */
8496317Sobrien
851543Srgrimes#endif /* !_VARARGS_H_ */
86