debian experimental exim-daemon-heavy config
[exim.git] / src / src / mytypes.h
CommitLineData
059ec3d9
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
f9ba5e22 5/* Copyright (c) University of Cambridge 1995 - 2018 */
1e1ddfac 6/* Copyright (c) The Exim Maintainers 2020 */
059ec3d9
PH
7/* See the file NOTICE for conditions of use and distribution. */
8
9
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
12local_scan.h includes it and exim.h includes them both (to get this earlier). */
13
14#ifndef MYTYPES_H
15#define MYTYPES_H
16
f3ebb786
JH
17# include <string.h>
18
d1406d48 19#ifndef FALSE
2f4df477 20# define FALSE 0
d1406d48
NM
21#endif
22
23#ifndef TRUE
2f4df477 24# define TRUE 1
d1406d48
NM
25#endif
26
27#ifndef TRUE_UNSET
2f4df477 28# define TRUE_UNSET 2
d1406d48 29#endif
059ec3d9
PH
30
31
32/* If gcc is being used to compile Exim, we can use its facility for checking
33the arguments of printf-like functions. This is done by a macro. */
34
b3c261f7 35#if defined(__GNUC__) || defined(__clang__)
268d00ff
JH
36# define PRINTF_FUNCTION(A,B) __attribute__((format(printf,A,B)))
37# define ARG_UNUSED __attribute__((__unused__))
38# define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1d1e7973
JH
39# define ALLOC __attribute__((malloc))
40# define ALLOC_SIZE(A) __attribute__((alloc_size(A)))
41# define NORETURN __attribute__((noreturn))
059ec3d9 42#else
2f4df477 43# define PRINTF_FUNCTION(A,B)
1d1e7973
JH
44# define ARG_UNUSED /**/
45# define WARN_UNUSED_RESULT /**/
46# define ALLOC /**/
47# define ALLOC_SIZE(A) /**/
48# define NORETURN /**/
059ec3d9
PH
49#endif
50
81f91683 51#ifdef WANT_DEEPER_PRINTF_CHECKS
2f4df477 52# define ALMOST_PRINTF(A, B) PRINTF_FUNCTION(A, B)
81f91683 53#else
2f4df477 54# define ALMOST_PRINTF(A, B)
81f91683
PP
55#endif
56
059ec3d9
PH
57
58/* Some operating systems (naughtily, imo) include a definition for "uchar" in
59the standard header files, so we use "uschar". Solaris has u_char in
60sys/types.h. This is just a typing convenience, of course. */
61
059ec3d9 62typedef unsigned char uschar;
a207d5dd 63typedef unsigned BOOL;
cd59ab18
PP
64/* We also have SIGNAL_BOOL, which requires signal.h be included, so is defined
65elsewhere */
059ec3d9
PH
66
67
68/* These macros save typing for the casting that is needed to cope with the
69mess that is "char" in ISO/ANSI C. Having now been bitten enough times by
70systems where "char" is actually signed, I've converted Exim to use entirely
71unsigned chars, except in a few special places such as arguments that are
72almost always literal strings. */
73
74#define CS (char *)
75#define CCS (const char *)
76#define CSS (char **)
77#define US (unsigned char *)
78#define CUS (const unsigned char *)
79#define USS (unsigned char **)
55414b25 80#define CUSS (const unsigned char **)
3d2e82c5 81#define CCSS (const char **)
059ec3d9
PH
82
83/* The C library string functions expect "char *" arguments. Use macros to
84avoid having to write a cast each time. We do this for string and file
85functions that are called quite often; for other calls to external libraries
86(which are on the whole special-purpose) we just use individual casts. */
87
88#define Uatoi(s) atoi(CCS(s))
89#define Uatol(s) atol(CCS(s))
90#define Uchdir(s) chdir(CCS(s))
91#define Uchmod(s,n) chmod(CCS(s),n)
059ec3d9 92#define Ufgets(b,n,f) fgets(CS(b),n,f)
9e21ce8f 93#define Ufopen(s,t) exim_fopen(CCS(s),CCS(t))
059ec3d9
PH
94#define Ulink(s,t) link(CCS(s),CCS(t))
95#define Ulstat(s,t) lstat(CCS(s),t)
96
9e21ce8f 97#ifdef O_BINARY /* This is for Cygwin, */
36eb5d3d
JH
98# define Uopen(s,n,m) exim_open(CCS(s),(n)|O_BINARY,m) /* where all files must */
99# define Uopen2(s,n) exim_open2(CCS(s),(n)|O_BINARY)
9e21ce8f 100#else /* be opened as binary */
36eb5d3d
JH
101# define Uopen(s,n,m) exim_open(CCS(s),n,m) /* to avoid problems */
102# define Uopen2(s,n) exim_open2(CCS(s),n)
9e21ce8f 103#endif /* with CRLF endings. */
059ec3d9
PH
104#define Uread(f,b,l) read(f,CS(b),l)
105#define Urename(s,t) rename(CCS(s),CCS(t))
106#define Ustat(s,t) stat(CCS(s),t)
059ec3d9
PH
107#define Ustrchr(s,n) US strchr(CCS(s),n)
108#define CUstrchr(s,n) CUS strchr(CCS(s),n)
109#define CUstrerror(n) CUS strerror(n)
110#define Ustrcmp(s,t) strcmp(CCS(s),CCS(t))
f3ebb786 111#define Ustrcpy_nt(s,t) strcpy(CS s, CCS t) /* no taint check */
059ec3d9
PH
112#define Ustrcspn(s,t) strcspn(CCS(s),CCS(t))
113#define Ustrftime(s,m,f,t) strftime(CS(s),m,f,t)
114#define Ustrlen(s) (int)strlen(CCS(s))
059ec3d9 115#define Ustrncmp(s,t,n) strncmp(CCS(s),CCS(t),n)
f3ebb786 116#define Ustrncpy_nt(s,t,n) strncpy(CS s, CCS t, n) /* no taint check */
059ec3d9
PH
117#define Ustrpbrk(s,t) strpbrk(CCS(s),CCS(t))
118#define Ustrrchr(s,n) US strrchr(CCS(s),n)
119#define CUstrrchr(s,n) CUS strrchr(CCS(s),n)
120#define Ustrspn(s,t) strspn(CCS(s),CCS(t))
121#define Ustrstr(s,t) US strstr(CCS(s),CCS(t))
122#define CUstrstr(s,t) CUS strstr(CCS(s),CCS(t))
123#define Ustrtod(s,t) strtod(CCS(s),CSS(t))
124#define Ustrtol(s,t,b) strtol(CCS(s),CSS(t),b)
125#define Ustrtoul(s,t,b) strtoul(CCS(s),CSS(t),b)
126#define Uunlink(s) unlink(CCS(s))
e59797e3 127
df92b047 128#if defined(EM_VERSION_C) || defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
36eb5d3d
JH
129# define Ustrcat(s,t) strcat(CS(s), CCS(t))
130# define Ustrcpy(s,t) strcpy(CS(s), CCS(t))
131# define Ustrncat(s,t,n) strncat(CS(s), CCS(t), n)
132# define Ustrncpy(s,t,n) strncpy(CS(s), CCS(t), n)
aaabfafe 133#else
36eb5d3d
JH
134# define Ustrcat(s,t) __Ustrcat(s, CUS(t), __FUNCTION__, __LINE__)
135# define Ustrcpy(s,t) __Ustrcpy(s, CUS(t), __FUNCTION__, __LINE__)
136# define Ustrncat(s,t,n) __Ustrncat(s, CUS(t), n, __FUNCTION__, __LINE__)
137# define Ustrncpy(s,t,n) __Ustrncpy(s, CUS(t), n, __FUNCTION__, __LINE__)
f3ebb786 138#endif
059ec3d9 139
f3ebb786 140#endif
059ec3d9 141/* End of mytypes.h */