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