Update all copyright messages to cover 1995 - 2009. Remove tab from exim_checkaccess.src
[exim.git] / src / src / mytypes.h
1 /* $Cambridge: exim/src/src/mytypes.h,v 1.7 2009/11/16 19:50:37 nm4 Exp $ */
2
3 /*************************************************
4 *     Exim - an Internet mail transport agent    *
5 *************************************************/
6
7 /* Copyright (c) University of Cambridge 1995 - 2009 */
8 /* See the file NOTICE for conditions of use and distribution. */
9
10
11 /* This header file contains type definitions and macros that I use as
12 "standard" in the code of Exim and its utilities. Make it idempotent because
13 local_scan.h includes it and exim.h includes them both (to get this earlier). */
14
15 #ifndef MYTYPES_H
16 #define MYTYPES_H
17
18 #ifndef FALSE
19 #define FALSE         0
20 #endif
21
22 #ifndef TRUE
23 #define TRUE          1
24 #endif
25
26 #ifndef TRUE_UNSET
27 #define TRUE_UNSET    2
28 #endif
29
30
31 /* If gcc is being used to compile Exim, we can use its facility for checking
32 the arguments of printf-like functions. This is done by a macro. */
33
34 #ifdef __GNUC__
35 #define PRINTF_FUNCTION(A,B)  __attribute__((format(printf,A,B)))
36 #else
37 #define PRINTF_FUNCTION(A,B)
38 #endif
39
40
41 /* Some operating systems (naughtily, imo) include a definition for "uchar" in
42 the standard header files, so we use "uschar". Solaris has u_char in
43 sys/types.h. This is just a typing convenience, of course. */
44
45 typedef int BOOL;
46 typedef unsigned char uschar;
47
48
49 /* These macros save typing for the casting that is needed to cope with the
50 mess that is "char" in ISO/ANSI C. Having now been bitten enough times by
51 systems where "char" is actually signed, I've converted Exim to use entirely
52 unsigned chars, except in a few special places such as arguments that are
53 almost always literal strings. */
54
55 #define CS   (char *)
56 #define CCS  (const char *)
57 #define CSS  (char **)
58 #define US   (unsigned char *)
59 #define CUS  (const unsigned char *)
60 #define USS  (unsigned char **)
61
62 /* The C library string functions expect "char *" arguments. Use macros to
63 avoid having to write a cast each time. We do this for string and file
64 functions that are called quite often; for other calls to external libraries
65 (which are on the whole special-purpose) we just use individual casts. */
66
67 #define Uatoi(s)           atoi(CCS(s))
68 #define Uatol(s)           atol(CCS(s))
69 #define Uchdir(s)          chdir(CCS(s))
70 #define Uchmod(s,n)        chmod(CCS(s),n)
71 #define Uchown(s,n,m)      chown(CCS(s),n,m)
72 #define Ufgets(b,n,f)      fgets(CS(b),n,f)
73 #define Ufopen(s,t)        fopen(CCS(s),CCS(t))
74 #define Ulink(s,t)         link(CCS(s),CCS(t))
75 #define Ulstat(s,t)        lstat(CCS(s),t)
76
77 #ifdef O_BINARY                                        /* This is for Cygwin,  */
78 #define Uopen(s,n,m)       open(CCS(s),(n)|O_BINARY,m) /* where all files must */
79 #else                                                  /* be opened as binary  */
80 #define Uopen(s,n,m)       open(CCS(s),n,m)            /* to avoid problems    */
81 #endif                                                 /* with CRLF endings.   */
82 #define Uread(f,b,l)       read(f,CS(b),l)
83 #define Urename(s,t)       rename(CCS(s),CCS(t))
84 #define Ustat(s,t)         stat(CCS(s),t)
85 #define Ustrcat(s,t)       strcat(CS(s),CCS(t))
86 #define Ustrchr(s,n)       US strchr(CCS(s),n)
87 #define CUstrchr(s,n)      CUS strchr(CCS(s),n)
88 #define CUstrerror(n)      CUS strerror(n)
89 #define Ustrcmp(s,t)       strcmp(CCS(s),CCS(t))
90 #define Ustrcpy(s,t)       strcpy(CS(s),CCS(t))
91 #define Ustrcspn(s,t)      strcspn(CCS(s),CCS(t))
92 #define Ustrftime(s,m,f,t) strftime(CS(s),m,f,t)
93 #define Ustrlen(s)         (int)strlen(CCS(s))
94 #define Ustrncat(s,t,n)    strncat(CS(s),CCS(t),n)
95 #define Ustrncmp(s,t,n)    strncmp(CCS(s),CCS(t),n)
96 #define Ustrncpy(s,t,n)    strncpy(CS(s),CCS(t),n)
97 #define Ustrpbrk(s,t)      strpbrk(CCS(s),CCS(t))
98 #define Ustrrchr(s,n)      US strrchr(CCS(s),n)
99 #define CUstrrchr(s,n)     CUS strrchr(CCS(s),n)
100 #define Ustrspn(s,t)       strspn(CCS(s),CCS(t))
101 #define Ustrstr(s,t)       US strstr(CCS(s),CCS(t))
102 #define CUstrstr(s,t)      CUS strstr(CCS(s),CCS(t))
103 #define Ustrtod(s,t)       strtod(CCS(s),CSS(t))
104 #define Ustrtol(s,t,b)     strtol(CCS(s),CSS(t),b)
105 #define Ustrtoul(s,t,b)    strtoul(CCS(s),CSS(t),b)
106 #define Uunlink(s)         unlink(CCS(s))
107 #endif
108
109 /* End of mytypes.h */