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