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