cdefs.h revision 83489
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Berkeley Software Design, Inc.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
3614495Shsu *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
3750477Speter * $FreeBSD: head/sys/sys/cdefs.h 83489 2001-09-15 03:41:00Z dillon $
381541Srgrimes */
391541Srgrimes
402165Spaul#ifndef	_SYS_CDEFS_H_
412165Spaul#define	_SYS_CDEFS_H_
421541Srgrimes
431541Srgrimes#if defined(__cplusplus)
441541Srgrimes#define	__BEGIN_DECLS	extern "C" {
4536449Sdt#define	__END_DECLS	}
461541Srgrimes#else
471541Srgrimes#define	__BEGIN_DECLS
481541Srgrimes#define	__END_DECLS
491541Srgrimes#endif
501541Srgrimes
511541Srgrimes/*
521541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
531541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
5436971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
5536971Sbde * mode -- there must be no spaces between its arguments, and for nested
5636971Sbde * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
5736971Sbde * concatenate double-quoted strings produced by the __STRING macro, but
5836971Sbde * this only works with ANSI C.
5925083Sjdp *
6025083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument
6125083Sjdp * first.  It is only available with ANSI C.
621541Srgrimes */
631541Srgrimes#if defined(__STDC__) || defined(__cplusplus)
641541Srgrimes#define	__P(protos)	protos		/* full-blown ANSI C */
655012Sbde#define	__CONCAT1(x,y)	x ## y
665012Sbde#define	__CONCAT(x,y)	__CONCAT1(x,y)
6725083Sjdp#define	__STRING(x)	#x		/* stringify without expanding x */
6825083Sjdp#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
691541Srgrimes
701541Srgrimes#define	__const		const		/* define reserved names to standard */
711541Srgrimes#define	__signed	signed
721541Srgrimes#define	__volatile	volatile
731541Srgrimes#if defined(__cplusplus)
741541Srgrimes#define	__inline	inline		/* convert to C++ keyword */
751541Srgrimes#else
761541Srgrimes#ifndef __GNUC__
771541Srgrimes#define	__inline			/* delete GCC keyword */
781541Srgrimes#endif /* !__GNUC__ */
791541Srgrimes#endif /* !__cplusplus */
801541Srgrimes
811541Srgrimes#else	/* !(__STDC__ || __cplusplus) */
821541Srgrimes#define	__P(protos)	()		/* traditional C preprocessor */
831541Srgrimes#define	__CONCAT(x,y)	x/**/y
841541Srgrimes#define	__STRING(x)	"x"
851541Srgrimes
861541Srgrimes#ifndef __GNUC__
871541Srgrimes#define	__const				/* delete pseudo-ANSI C keywords */
881541Srgrimes#define	__inline
891541Srgrimes#define	__signed
901541Srgrimes#define	__volatile
911541Srgrimes/*
921541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords
931541Srgrimes * deleted from the program and old programs will want them left alone.
941541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords
951541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
961541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if
971541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
981541Srgrimes */
991541Srgrimes#ifndef	NO_ANSI_KEYWORDS
1001541Srgrimes#define	const				/* delete ANSI C keywords */
1011541Srgrimes#define	inline
1021541Srgrimes#define	signed
1031541Srgrimes#define	volatile
1045209Snate#endif	/* !NO_ANSI_KEYWORDS */
10515243Sbde#endif	/* !__GNUC__ */
1061541Srgrimes#endif	/* !(__STDC__ || __cplusplus) */
1071541Srgrimes
1081541Srgrimes/*
10938509Sbde * Compiler-dependent macros to help declare dead (non-returning) and
11038509Sbde * pure (no side effects) functions, and unused variables.  They are
11138509Sbde * null except for versions of gcc that are known to support the features
11238509Sbde * properly (old versions of gcc-2 supported the dead and pure features
11338509Sbde * in a different (wrong) way).
1141541Srgrimes */
11538509Sbde#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
11683444Sasmodai#define	__attribute__(x)
11783443Sasmodai#define	__dead2
11883443Sasmodai#define	__pure2
11983443Sasmodai#define	__unused
1202059Sdg#endif
12117648Speter#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
12283443Sasmodai#define	__dead2		__attribute__((__noreturn__))
12383443Sasmodai#define	__pure2		__attribute__((__const__))
12483443Sasmodai#define	__unused
1251541Srgrimes#endif
12677631Sobrien#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3
12783443Sasmodai#define	__dead2		__attribute__((__noreturn__))
12883443Sasmodai#define	__pure2		__attribute__((__const__))
12983443Sasmodai#define	__unused	__attribute__((__unused__))
13017648Speter#endif
1311541Srgrimes
13238509Sbde/*
13338509Sbde * Compiler-dependent macros to declare that functions take printf-like
13438509Sbde * or scanf-like arguments.  They are null except for versions of gcc
13538509Sbde * that are known to support the features properly (old versions of gcc-2
13638509Sbde * didn't permit keeping the keywords out of the application namespace).
13738509Sbde */
13837614Sbde#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
13937614Sbde#define	__printflike(fmtarg, firstvararg)
14037614Sbde#define	__scanflike(fmtarg, firstvararg)
14137614Sbde#else
14237614Sbde#define	__printflike(fmtarg, firstvararg) \
14337614Sbde	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
14437614Sbde#define	__scanflike(fmtarg, firstvararg) \
14537614Sbde	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
14637614Sbde#endif
14737614Sbde
14840716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
14940736Sjdp#if __FreeBSD_cc_version >= 300001
15040716Sjdp#define	__printf0like(fmtarg, firstvararg) \
15140716Sjdp	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
15240716Sjdp#else
15340716Sjdp#define	__printf0like(fmtarg, firstvararg)
15440716Sjdp#endif
15540716Sjdp
1565209Snate#ifdef __GNUC__
15783443Sasmodai#define	__strong_reference(sym,aliassym)	\
15858256Sjasone	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));
15937052Speter#ifdef __ELF__
1605209Snate#ifdef __STDC__
16137052Speter#define	__weak_reference(sym,alias)	\
16237052Speter	__asm__(".weak " #alias);	\
16337862Sdfr	__asm__(".equ "  #alias ", " #sym)
16437052Speter#define	__warn_references(sym,msg)	\
16537052Speter	__asm__(".section .gnu.warning." #sym);	\
16639502Sjdp	__asm__(".asciz \"" msg "\"");	\
16737052Speter	__asm__(".previous")
16837052Speter#else
16937052Speter#define	__weak_reference(sym,alias)	\
17037052Speter	__asm__(".weak alias");		\
17137862Sdfr	__asm__(".equ alias, sym")
17237052Speter#define	__warn_references(sym,msg)	\
17337052Speter	__asm__(".section .gnu.warning.sym"); \
17439502Sjdp	__asm__(".asciz \"msg\"");	\
17537052Speter	__asm__(".previous")
17637052Speter#endif	/* __STDC__ */
17737052Speter#else	/* !__ELF__ */
17837052Speter#ifdef __STDC__
17983443Sasmodai#define	__weak_reference(sym,alias)	\
1805209Snate	__asm__(".stabs \"_" #alias "\",11,0,0,0");	\
1815209Snate	__asm__(".stabs \"_" #sym "\",1,0,0,0")
18283443Sasmodai#define	__warn_references(sym,msg)	\
1835209Snate	__asm__(".stabs \"" msg "\",30,0,0,0");		\
1845209Snate	__asm__(".stabs \"_" #sym "\",1,0,0,0")
1855209Snate#else
18683443Sasmodai#define	__weak_reference(sym,alias)	\
1875209Snate	__asm__(".stabs \"_/**/alias\",11,0,0,0");	\
1885209Snate	__asm__(".stabs \"_/**/sym\",1,0,0,0")
18983443Sasmodai#define	__warn_references(sym,msg)	\
1905209Snate	__asm__(".stabs msg,30,0,0,0");			\
1915209Snate	__asm__(".stabs \"_/**/sym\",1,0,0,0")
19237052Speter#endif	/* __STDC__ */
19337052Speter#endif	/* __ELF__ */
19437052Speter#endif	/* __GNUC__ */
1955209Snate
19683049Speter#ifdef __GNUC__
19783049Speter#ifdef __ELF__
19850614Speter#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
19950614Speter#else
20083049Speter#define	__IDSTRING(name,string)	__asm__(".data\n\t.asciz\t\"" string "\"\n\t.previous")
20183049Speter#endif
20283049Speter#else
20383049Speter/*
20483049Speter * This doesn't work in header files. But it may be better than nothing.
20583056Speter * The alternative is: #define __IDSTRING(name,string)  [nothing]
20683049Speter */
20736971Sbde#define	__IDSTRING(name,string)	static const char name[] __unused = string
20850614Speter#endif
20931707Spst
21031707Spst#ifndef	__RCSID
21183049Speter#define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
21231707Spst#endif
21331707Spst
21483489Sdillon#ifndef	__FBSDID
21583489Sdillon#if !defined(lint) && !defined(STRIP_FBSDID)
21683489Sdillon#define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
21783489Sdillon#else
21883489Sdillon#define	__FBSDID(s)
21983489Sdillon#endif
22083489Sdillon#endif
22183489Sdillon
22231707Spst#ifndef	__RCSID_SOURCE
22383049Speter#define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
22431707Spst#endif
22531707Spst
22631707Spst#ifndef	__COPYRIGHT
22783049Speter#define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
22831707Spst#endif
22931707Spst
23074070Sbillf#ifndef	__DECONST
23174070Sbillf#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
23274070Sbillf#endif
23374070Sbillf
23474070Sbillf#ifndef	__DEVOLATILE
23574070Sbillf#define	__DEVOLATILE(type, var)	((type)(uintptr_t)(volatile void *)(var))
23674070Sbillf#endif
23774070Sbillf
23874070Sbillf#ifndef	__DEQUALIFY
23974070Sbillf#define	__DEQUALIFY(type, var)	((type)(uintptr_t)(const volatile void *)(var))
24074070Sbillf#endif
24174070Sbillf
2422212Sbde#endif /* !_SYS_CDEFS_H_ */
243