1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
10 /* This header file contains type definitions and macros that I use as
11 "standard" in the code of Exim and its utilities. Make it idempotent because
12 local_scan.h includes it and exim.h includes them both (to get this earlier). */
32 /* If gcc is being used to compile Exim, we can use its facility for checking
33 the arguments of printf-like functions. This is done by a macro.
34 OpenBSD has unfortunately taken to objecting to use of %n in printf
35 so we have to give up on all of the available parameter checking. */
37 #if defined(__GNUC__) || defined(__clang__)
39 # define PRINTF_FUNCTION(A,B) __attribute__((format(printf,A,B)))
41 # define ARG_UNUSED __attribute__((__unused__))
42 # define FUNC_MAYBE_UNUSED __attribute__((__unused__))
43 # define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
44 # define ALLOC __attribute__((malloc))
45 # define NORETURN __attribute__((noreturn))
47 # define ALLOC_SIZE(A) __attribute__((alloc_size(A)))
49 # define ALLOC_SIZE(A) /**/
52 # define ARG_UNUSED /**/
53 # define FUNC_MAYBE_UNUSED /**/
54 # define WARN_UNUSED_RESULT /**/
56 # define ALLOC_SIZE(A) /**/
57 # define NORETURN /**/
60 #ifndef PRINTF_FUNCTION
61 # define PRINTF_FUNCTION(A,B) /**/
64 #ifdef WANT_DEEPER_PRINTF_CHECKS
65 # define ALMOST_PRINTF(A, B) PRINTF_FUNCTION(A, B)
67 # define ALMOST_PRINTF(A, B) /**/
71 /* Some operating systems (naughtily, imo) include a definition for "uchar" in
72 the standard header files, so we use "uschar". Solaris has u_char in
73 sys/types.h. This is just a typing convenience, of course. */
75 typedef unsigned char uschar;
76 typedef unsigned BOOL;
77 /* We also have SIGNAL_BOOL, which requires signal.h be included, so is defined
81 /* These macros save typing for the casting that is needed to cope with the
82 mess that is "char" in ISO/ANSI C. Having now been bitten enough times by
83 systems where "char" is actually signed, I've converted Exim to use entirely
84 unsigned chars, except in a few special places such as arguments that are
85 almost always literal strings. */
88 #define CCS (const char *)
90 #define US (unsigned char *)
91 #define CUS (const unsigned char *)
92 #define USS (unsigned char **)
93 #define CUSS (const unsigned char **)
94 #define CCSS (const char **)
96 /* The C library string functions expect "char *" arguments. Use macros to
97 avoid having to write a cast each time. We do this for string and file
98 functions that are called quite often; for other calls to external libraries
99 (which are on the whole special-purpose) we just use individual casts. */
101 #define Uatoi(s) atoi(CCS(s))
102 #define Uatol(s) atol(CCS(s))
103 #define Uchdir(s) chdir(CCS(s))
104 #define Uchmod(s,n) chmod(CCS(s),n)
105 #define Ufgets(b,n,f) fgets(CS(b),n,f)
106 #define Ufopen(s,t) exim_fopen(CCS(s),CCS(t))
107 #define Ulink(s,t) link(CCS(s),CCS(t))
108 #define Ulstat(s,t) lstat(CCS(s),t)
110 #ifdef O_BINARY /* This is for Cygwin, */
111 # define Uopen(s,n,m) exim_open(CCS(s),(n)|O_BINARY,m) /* where all files must */
112 # define Uopen2(s,n) exim_open2(CCS(s),(n)|O_BINARY)
113 #else /* be opened as binary */
114 # define Uopen(s,n,m) exim_open(CCS(s),n,m) /* to avoid problems */
115 # define Uopen2(s,n) exim_open2(CCS(s),n)
116 #endif /* with CRLF endings. */
117 #define Uread(f,b,l) read(f,CS(b),l)
118 #define Urename(s,t) rename(CCS(s),CCS(t))
119 #define Ustat(s,t) stat(CCS(s),t)
120 #define Ustrchr(s,n) US strchr(CCS(s),n)
121 #define CUstrchr(s,n) CUS strchr(CCS(s),n)
122 #define CUstrerror(n) CUS strerror(n)
123 #define Ustrcmp(s,t) strcmp(CCS(s),CCS(t))
124 #define Ustrcpy_nt(s,t) strcpy(CS s, CCS t) /* no taint check */
125 #define Ustrcspn(s,t) strcspn(CCS(s),CCS(t))
126 #define Ustrftime(s,m,f,t) strftime(CS(s),m,f,t)
127 #define Ustrlen(s) (int)strlen(CCS(s))
128 #define Ustrncmp(s,t,n) strncmp(CCS(s),CCS(t),n)
129 #define Ustrncpy_nt(s,t,n) strncpy(CS s, CCS t, n) /* no taint check */
130 #define Ustrpbrk(s,t) strpbrk(CCS(s),CCS(t))
131 #define Ustrrchr(s,n) US strrchr(CCS(s),n)
132 #define CUstrrchr(s,n) CUS strrchr(CCS(s),n)
133 #define Ustrspn(s,t) strspn(CCS(s),CCS(t))
134 #define Ustrstr(s,t) US strstr(CCS(s),CCS(t))
135 #define CUstrstr(s,t) CUS strstr(CCS(s),CCS(t))
136 #define Ustrtod(s,t) strtod(CCS(s),CSS(t))
137 #define Ustrtol(s,t,b) strtol(CCS(s),CSS(t),b)
138 #define Ustrtoul(s,t,b) strtoul(CCS(s),CSS(t),b)
139 #define Uunlink(s) unlink(CCS(s))
141 #if defined(EM_VERSION_C) || defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
142 # define Ustrcat(s,t) strcat(CS(s), CCS(t))
143 # define Ustrcpy(s,t) strcpy(CS(s), CCS(t))
144 # define Ustrncat(s,t,n) strncat(CS(s), CCS(t), n)
145 # define Ustrncpy(s,t,n) strncpy(CS(s), CCS(t), n)
147 # define Ustrcat(s,t) __Ustrcat(s, CUS(t), __FUNCTION__, __LINE__)
148 # define Ustrcpy(s,t) __Ustrcpy(s, CUS(t), __FUNCTION__, __LINE__)
149 # define Ustrncat(s,t,n) __Ustrncat(s, CUS(t), n, __FUNCTION__, __LINE__)
150 # define Ustrncpy(s,t,n) __Ustrncpy(s, CUS(t), n, __FUNCTION__, __LINE__)
154 /* End of mytypes.h */