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