1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  *	$Id: cdefs.h,v 1.15.2.1 2003/12/05 22:44:17 ca Exp $
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*7c478bd9Sstevel@tonic-gate 
14*7c478bd9Sstevel@tonic-gate /*
15*7c478bd9Sstevel@tonic-gate **  libsm C language portability macros
16*7c478bd9Sstevel@tonic-gate **  See libsm/cdefs.html for documentation.
17*7c478bd9Sstevel@tonic-gate */
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate #ifndef SM_CDEFS_H
20*7c478bd9Sstevel@tonic-gate # define SM_CDEFS_H
21*7c478bd9Sstevel@tonic-gate 
22*7c478bd9Sstevel@tonic-gate # include <sm/config.h>
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate **  BSD and Linux have <sys/cdefs.h> which defines a set of C language
26*7c478bd9Sstevel@tonic-gate **  portability macros that are a defacto standard in the open source
27*7c478bd9Sstevel@tonic-gate **  community.
28*7c478bd9Sstevel@tonic-gate */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate # if SM_CONF_SYS_CDEFS_H
31*7c478bd9Sstevel@tonic-gate #  include <sys/cdefs.h>
32*7c478bd9Sstevel@tonic-gate # endif /* SM_CONF_SYS_CDEFS_H */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate **  Define the standard C language portability macros
36*7c478bd9Sstevel@tonic-gate **  for platforms that lack <sys/cdefs.h>.
37*7c478bd9Sstevel@tonic-gate */
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate # if !SM_CONF_SYS_CDEFS_H
40*7c478bd9Sstevel@tonic-gate #  if defined(__cplusplus)
41*7c478bd9Sstevel@tonic-gate #   define	__BEGIN_DECLS	extern "C" {
42*7c478bd9Sstevel@tonic-gate #   define	__END_DECLS	};
43*7c478bd9Sstevel@tonic-gate #  else /* defined(__cplusplus) */
44*7c478bd9Sstevel@tonic-gate #   define	__BEGIN_DECLS
45*7c478bd9Sstevel@tonic-gate #   define	__END_DECLS
46*7c478bd9Sstevel@tonic-gate #  endif /* defined(__cplusplus) */
47*7c478bd9Sstevel@tonic-gate #  if defined(__STDC__) || defined(__cplusplus)
48*7c478bd9Sstevel@tonic-gate #   ifndef __P
49*7c478bd9Sstevel@tonic-gate #    define	__P(protos)	protos
50*7c478bd9Sstevel@tonic-gate #   endif /* __P */
51*7c478bd9Sstevel@tonic-gate #   define	__CONCAT(x,y)	x ## y
52*7c478bd9Sstevel@tonic-gate #   define	__STRING(x)	#x
53*7c478bd9Sstevel@tonic-gate #  else /* defined(__STDC__) || defined(__cplusplus) */
54*7c478bd9Sstevel@tonic-gate #   define	__P(protos)	()
55*7c478bd9Sstevel@tonic-gate #   define	__CONCAT(x,y)	x/**/y
56*7c478bd9Sstevel@tonic-gate #   define	__STRING(x)	"x"
57*7c478bd9Sstevel@tonic-gate #   define	const
58*7c478bd9Sstevel@tonic-gate #   define	signed
59*7c478bd9Sstevel@tonic-gate #   define	volatile
60*7c478bd9Sstevel@tonic-gate #  endif /* defined(__STDC__) || defined(__cplusplus) */
61*7c478bd9Sstevel@tonic-gate # endif /* !SM_CONF_SYS_CDEFS_H */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate **  Define SM_DEAD, a macro used to declare functions that do not return
65*7c478bd9Sstevel@tonic-gate **  to their caller.
66*7c478bd9Sstevel@tonic-gate */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate # ifndef SM_DEAD
69*7c478bd9Sstevel@tonic-gate #  if __GNUC__ >= 2
70*7c478bd9Sstevel@tonic-gate #   if __GNUC__ == 2 && __GNUC_MINOR__ < 5
71*7c478bd9Sstevel@tonic-gate #    define SM_DEAD(proto) volatile proto
72*7c478bd9Sstevel@tonic-gate #    define SM_DEAD_D volatile
73*7c478bd9Sstevel@tonic-gate #   else /* __GNUC__ == 2 && __GNUC_MINOR__ < 5 */
74*7c478bd9Sstevel@tonic-gate #    define SM_DEAD(proto) proto __attribute__((__noreturn__))
75*7c478bd9Sstevel@tonic-gate #    define SM_DEAD_D
76*7c478bd9Sstevel@tonic-gate #   endif /* __GNUC__ == 2 && __GNUC_MINOR__ < 5 */
77*7c478bd9Sstevel@tonic-gate #  else /* __GNUC__ >= 2 */
78*7c478bd9Sstevel@tonic-gate #   define SM_DEAD(proto) proto
79*7c478bd9Sstevel@tonic-gate #   define SM_DEAD_D
80*7c478bd9Sstevel@tonic-gate #  endif /* __GNUC__ >= 2 */
81*7c478bd9Sstevel@tonic-gate # endif /* SM_DEAD */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate **  Define SM_UNUSED, a macro used to declare variables that may be unused.
85*7c478bd9Sstevel@tonic-gate */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate # ifndef SM_UNUSED
88*7c478bd9Sstevel@tonic-gate #  if __GNUC__ >= 2
89*7c478bd9Sstevel@tonic-gate #   if __GNUC__ == 2 && __GNUC_MINOR__ < 7
90*7c478bd9Sstevel@tonic-gate #    define SM_UNUSED(decl) decl
91*7c478bd9Sstevel@tonic-gate #   else /* __GNUC__ == 2 && __GNUC_MINOR__ < 7 */
92*7c478bd9Sstevel@tonic-gate #    define SM_UNUSED(decl) decl __attribute__((__unused__))
93*7c478bd9Sstevel@tonic-gate #   endif /* __GNUC__ == 2 && __GNUC_MINOR__ < 7 */
94*7c478bd9Sstevel@tonic-gate #  else /* __GNUC__ >= 2 */
95*7c478bd9Sstevel@tonic-gate #   define SM_UNUSED(decl) decl
96*7c478bd9Sstevel@tonic-gate #  endif /* __GNUC__ >= 2 */
97*7c478bd9Sstevel@tonic-gate # endif /* SM_UNUSED */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate **  The SM_NONVOLATILE macro is used to declare variables that are not
101*7c478bd9Sstevel@tonic-gate **  volatile, but which must be declared volatile when compiling with
102*7c478bd9Sstevel@tonic-gate **  gcc -O -Wall in order to suppress bogus warning messages.
103*7c478bd9Sstevel@tonic-gate **
104*7c478bd9Sstevel@tonic-gate **  Variables that actually are volatile should be declared volatile
105*7c478bd9Sstevel@tonic-gate **  using the "volatile" keyword.  If a variable actually is volatile,
106*7c478bd9Sstevel@tonic-gate **  then SM_NONVOLATILE should not be used.
107*7c478bd9Sstevel@tonic-gate **
108*7c478bd9Sstevel@tonic-gate **  To compile sendmail with gcc and see all non-bogus warnings,
109*7c478bd9Sstevel@tonic-gate **  you should use
110*7c478bd9Sstevel@tonic-gate **	gcc -O -Wall -DSM_OMIT_BOGUS_WARNINGS ...
111*7c478bd9Sstevel@tonic-gate **  Do not use -DSM_OMIT_BOGUS_WARNINGS when compiling the production
112*7c478bd9Sstevel@tonic-gate **  version of sendmail, because there is a performance hit.
113*7c478bd9Sstevel@tonic-gate */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate # ifdef SM_OMIT_BOGUS_WARNINGS
116*7c478bd9Sstevel@tonic-gate #  define SM_NONVOLATILE volatile
117*7c478bd9Sstevel@tonic-gate # else /* SM_OMIT_BOGUS_WARNINGS */
118*7c478bd9Sstevel@tonic-gate #  define SM_NONVOLATILE
119*7c478bd9Sstevel@tonic-gate # endif /* SM_OMIT_BOGUS_WARNINGS */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate **  Turn on format string argument checking.
123*7c478bd9Sstevel@tonic-gate */
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate # ifndef SM_CONF_FORMAT_TEST
126*7c478bd9Sstevel@tonic-gate #  if __GNUC__ == 2 && __GNUC_MINOR__ >= 7
127*7c478bd9Sstevel@tonic-gate #   define SM_CONF_FORMAT_TEST	1
128*7c478bd9Sstevel@tonic-gate #  else /* __GNUC__ == 2 && __GNUC_MINOR__ >= 7 */
129*7c478bd9Sstevel@tonic-gate #   define SM_CONF_FORMAT_TEST	0
130*7c478bd9Sstevel@tonic-gate #  endif /* __GNUC__ == 2 && __GNUC_MINOR__ >= 7 */
131*7c478bd9Sstevel@tonic-gate # endif /* SM_CONF_FORMAT_TEST */
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate # ifndef PRINTFLIKE
134*7c478bd9Sstevel@tonic-gate #  if SM_CONF_FORMAT_TEST
135*7c478bd9Sstevel@tonic-gate #   define PRINTFLIKE(x,y) __attribute__ ((__format__ (__printf__, x, y)))
136*7c478bd9Sstevel@tonic-gate #  else /* SM_CONF_FORMAT_TEST */
137*7c478bd9Sstevel@tonic-gate #   define PRINTFLIKE(x,y)
138*7c478bd9Sstevel@tonic-gate #  endif /* SM_CONF_FORMAT_TEST */
139*7c478bd9Sstevel@tonic-gate # endif /* ! PRINTFLIKE */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate # ifndef SCANFLIKE
142*7c478bd9Sstevel@tonic-gate #  if SM_CONF_FORMAT_TEST
143*7c478bd9Sstevel@tonic-gate #   define SCANFLIKE(x,y) __attribute__ ((__format__ (__scanf__, x, y)))
144*7c478bd9Sstevel@tonic-gate #  else /* SM_CONF_FORMAT_TEST */
145*7c478bd9Sstevel@tonic-gate #   define SCANFLIKE(x,y)
146*7c478bd9Sstevel@tonic-gate #  endif /* SM_CONF_FORMAT_TEST */
147*7c478bd9Sstevel@tonic-gate # endif /* ! SCANFLIKE */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #endif /* ! SM_CDEFS_H */
150