1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2012 */
6 /* See the file NOTICE for conditions of use and distribution. */
9 /* This header file contains type definitions and macros that I use as
10 "standard" in the code of Exim and its utilities. Make it idempotent because
11 local_scan.h includes it and exim.h includes them both (to get this earlier). */
29 /* If gcc is being used to compile Exim, we can use its facility for checking
30 the arguments of printf-like functions. This is done by a macro. */
32 #if defined(__GNUC__) || defined(__clang__)
33 #define PRINTF_FUNCTION(A,B) __attribute__((format(printf,A,B)))
34 #define ARG_UNUSED __attribute__((__unused__))
36 #define PRINTF_FUNCTION(A,B)
37 #define ARG_UNUSED /**/
40 #ifdef WANT_DEEPER_PRINTF_CHECKS
41 #define ALMOST_PRINTF(A, B) PRINTF_FUNCTION(A, B)
43 #define ALMOST_PRINTF(A, B)
47 /* Some operating systems (naughtily, imo) include a definition for "uchar" in
48 the standard header files, so we use "uschar". Solaris has u_char in
49 sys/types.h. This is just a typing convenience, of course. */
51 typedef unsigned char uschar;
53 /* We also have SIGNAL_BOOL, which requires signal.h be included, so is defined
57 /* These macros save typing for the casting that is needed to cope with the
58 mess that is "char" in ISO/ANSI C. Having now been bitten enough times by
59 systems where "char" is actually signed, I've converted Exim to use entirely
60 unsigned chars, except in a few special places such as arguments that are
61 almost always literal strings. */
64 #define CCS (const char *)
66 #define US (unsigned char *)
67 #define CUS (const unsigned char *)
68 #define USS (unsigned char **)
70 /* The C library string functions expect "char *" arguments. Use macros to
71 avoid having to write a cast each time. We do this for string and file
72 functions that are called quite often; for other calls to external libraries
73 (which are on the whole special-purpose) we just use individual casts. */
75 #define Uatoi(s) atoi(CCS(s))
76 #define Uatol(s) atol(CCS(s))
77 #define Uchdir(s) chdir(CCS(s))
78 #define Uchmod(s,n) chmod(CCS(s),n)
79 #define Uchown(s,n,m) chown(CCS(s),n,m)
80 #define Ufgets(b,n,f) fgets(CS(b),n,f)
81 #define Ufopen(s,t) fopen(CCS(s),CCS(t))
82 #define Ulink(s,t) link(CCS(s),CCS(t))
83 #define Ulstat(s,t) lstat(CCS(s),t)
85 #ifdef O_BINARY /* This is for Cygwin, */
86 #define Uopen(s,n,m) open(CCS(s),(n)|O_BINARY,m) /* where all files must */
87 #else /* be opened as binary */
88 #define Uopen(s,n,m) open(CCS(s),n,m) /* to avoid problems */
89 #endif /* with CRLF endings. */
90 #define Uread(f,b,l) read(f,CS(b),l)
91 #define Urename(s,t) rename(CCS(s),CCS(t))
92 #define Ustat(s,t) stat(CCS(s),t)
93 #define Ustrcat(s,t) strcat(CS(s),CCS(t))
94 #define Ustrchr(s,n) US strchr(CCS(s),n)
95 #define CUstrchr(s,n) CUS strchr(CCS(s),n)
96 #define CUstrerror(n) CUS strerror(n)
97 #define Ustrcmp(s,t) strcmp(CCS(s),CCS(t))
98 #define Ustrcpy(s,t) strcpy(CS(s),CCS(t))
99 #define Ustrcspn(s,t) strcspn(CCS(s),CCS(t))
100 #define Ustrftime(s,m,f,t) strftime(CS(s),m,f,t)
101 #define Ustrlen(s) (int)strlen(CCS(s))
102 #define Ustrncat(s,t,n) strncat(CS(s),CCS(t),n)
103 #define Ustrncmp(s,t,n) strncmp(CCS(s),CCS(t),n)
104 #define Ustrncpy(s,t,n) strncpy(CS(s),CCS(t),n)
105 #define Ustrpbrk(s,t) strpbrk(CCS(s),CCS(t))
106 #define Ustrrchr(s,n) US strrchr(CCS(s),n)
107 #define CUstrrchr(s,n) CUS strrchr(CCS(s),n)
108 #define Ustrspn(s,t) strspn(CCS(s),CCS(t))
109 #define Ustrstr(s,t) US strstr(CCS(s),CCS(t))
110 #define CUstrstr(s,t) CUS strstr(CCS(s),CCS(t))
111 #define Ustrtod(s,t) strtod(CCS(s),CSS(t))
112 #define Ustrtol(s,t,b) strtol(CCS(s),CSS(t),b)
113 #define Ustrtoul(s,t,b) strtoul(CCS(s),CSS(t),b)
114 #define Uunlink(s) unlink(CCS(s))
117 /* End of mytypes.h */