debian experimental exim-daemon-heavy config
[exim.git] / src / src / mytypes.h
... / ...
CommitLineData
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
5/* Copyright (c) University of Cambridge 1995 - 2018 */
6/* Copyright (c) The Exim Maintainers 2020 */
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
17# include <string.h>
18
19#ifndef FALSE
20# define FALSE 0
21#endif
22
23#ifndef TRUE
24# define TRUE 1
25#endif
26
27#ifndef TRUE_UNSET
28# define TRUE_UNSET 2
29#endif
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
35#if defined(__GNUC__) || defined(__clang__)
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__))
39# define ALLOC __attribute__((malloc))
40# define ALLOC_SIZE(A) __attribute__((alloc_size(A)))
41# define NORETURN __attribute__((noreturn))
42#else
43# define PRINTF_FUNCTION(A,B)
44# define ARG_UNUSED /**/
45# define WARN_UNUSED_RESULT /**/
46# define ALLOC /**/
47# define ALLOC_SIZE(A) /**/
48# define NORETURN /**/
49#endif
50
51#ifdef WANT_DEEPER_PRINTF_CHECKS
52# define ALMOST_PRINTF(A, B) PRINTF_FUNCTION(A, B)
53#else
54# define ALMOST_PRINTF(A, B)
55#endif
56
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
62typedef unsigned char uschar;
63typedef unsigned BOOL;
64/* We also have SIGNAL_BOOL, which requires signal.h be included, so is defined
65elsewhere */
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 **)
80#define CUSS (const unsigned char **)
81#define CCSS (const char **)
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)
92#define Ufgets(b,n,f) fgets(CS(b),n,f)
93#define Ufopen(s,t) exim_fopen(CCS(s),CCS(t))
94#define Ulink(s,t) link(CCS(s),CCS(t))
95#define Ulstat(s,t) lstat(CCS(s),t)
96
97#ifdef O_BINARY /* This is for Cygwin, */
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)
100#else /* be opened as binary */
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)
103#endif /* with CRLF endings. */
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)
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))
111#define Ustrcpy_nt(s,t) strcpy(CS s, CCS t) /* no taint check */
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))
115#define Ustrncmp(s,t,n) strncmp(CCS(s),CCS(t),n)
116#define Ustrncpy_nt(s,t,n) strncpy(CS s, CCS t, n) /* no taint check */
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))
127
128#if defined(EM_VERSION_C) || defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
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)
133#else
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__)
138#endif
139
140#endif
141/* End of mytypes.h */