]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/bc_types.h
9e9ea174d9a7863b7eddb684b0e739b1c67ed408
[bacula/bacula] / bacula / src / bc_types.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21     Define integer types for Bacula -- Kern Sibbald
22
23     Integer types.  These types should be be used in all
24     contexts in which the length of an integer stored on
25     removable media must be known regardless of the
26     architecture of the platform.
27
28     Bacula types are:
29
30     int8_t,  int16_t,  int32_t,  int64_t
31     uint8_t, uint16_t, uint32_t, uint64_t
32
33     Also, we define types such as file address lengths.
34
35  */
36
37
38 #ifndef __bc_types_INCLUDED
39 #define __bc_types_INCLUDED
40
41 /*
42  * These are the sizes of the current definitions of database
43  *  Ids.  In general, FileId_t can be set to uint64_t and it
44  *  *should* work.  Users have reported back that it does work
45  *  for PostgreSQL.  For the other types, all places in Bacula
46  *  have been converted, but no one has actually tested it.
47  * In principle, the only field that really should need to be
48  *  64 bits is the FileId_t
49  */
50 typedef uint64_t FileId_t;
51 typedef uint32_t DBId_t;              /* general DB id type */
52 typedef uint32_t JobId_t;
53
54
55 typedef char POOLMEM;
56
57
58 /* Types */
59
60 /* If sys/types.h does not supply intXX_t, supply them ourselves */
61 /* (or die trying) */
62
63 #ifndef HAVE_U_INT
64 typedef unsigned int u_int;
65 #endif
66
67 #ifndef HAVE_INTXX_T
68 # if (SIZEOF_CHAR == 1)
69 typedef signed char int8_t;
70 # else
71 #  error "8 bit int type not found."
72 # endif
73 # if (SIZEOF_SHORT_INT == 2)
74 typedef short int int16_t;
75 # else
76 #  error "16 bit int type not found."
77 # endif
78 # if (SIZEOF_INT == 4)
79 typedef int int32_t;
80 # else
81 #  error "32 bit int type not found."
82 # endif
83 #endif
84
85 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */
86 #ifndef HAVE_U_INTXX_T
87 # ifdef HAVE_UINTXX_T
88 typedef uint8_t u_int8_t;
89 typedef uint16_t u_int16_t;
90 typedef uint32_t u_int32_t;
91 # define HAVE_U_INTXX_T 1
92 # else
93 #  if (SIZEOF_CHAR == 1)
94 typedef unsigned char u_int8_t;
95 #  else
96 #   error "8 bit int type not found. Required!"
97 #  endif
98 #  if (SIZEOF_SHORT_INT == 2)
99 typedef unsigned short int u_int16_t;
100 #  else
101 #   error "16 bit int type not found. Required!"
102 #  endif
103 #  if (SIZEOF_INT == 4)
104 typedef unsigned int u_int32_t;
105 #  else
106 #   error "32 bit int type not found. Required!"
107 #  endif
108 # endif
109 #endif
110
111 /* 64-bit types */
112 #ifndef HAVE_INT64_T
113 # if (SIZEOF_LONG_LONG_INT == 8)
114 typedef long long int int64_t;
115 #   define HAVE_INT64_T 1
116 # else
117 #  if (SIZEOF_LONG_INT == 8)
118 typedef long int int64_t;
119 #   define HAVE_INT64_T 1
120 #  endif
121 # endif
122 #endif
123
124 #ifndef HAVE_INTMAX_T
125 # ifdef HAVE_INT64_T
126 typedef int64_t intmax_t;
127 # else
128 #   error "64 bit type not found. Required!"
129 # endif
130 #endif
131
132 #ifndef HAVE_U_INT64_T
133 # if (SIZEOF_LONG_LONG_INT == 8)
134 typedef unsigned long long int u_int64_t;
135 #   define HAVE_U_INT64_T 1
136 # else
137 #  if (SIZEOF_LONG_INT == 8)
138 typedef unsigned long int u_int64_t;
139 #   define HAVE_U_INT64_T 1
140 #  else
141 #   error "64 bit type not found. Required!"
142 #  endif
143 # endif
144 #endif
145
146 #ifndef HAVE_U_INTMAX_T
147 # ifdef HAVE_U_INT64_T
148 typedef u_int64_t u_intmax_t;
149 # else
150 #   error "64 bit type not found. Required!"
151 # endif
152 #endif
153
154 #ifndef HAVE_INTPTR_T
155 #define HAVE_INTPTR_T 1
156 # if (SIZEOF_INT_P == 4)
157 typedef int32_t intptr_t;
158 # else
159 #  if (SIZEOF_INT_P == 8)
160 typedef int64_t intptr_t;
161 #  else
162 #   error "Can't find sizeof pointer. Required!"
163 #  endif
164 # endif
165 #endif
166
167 #ifndef HAVE_UINTPTR_T
168 #define HAVE_UINTPTR_T 1
169 # if (SIZEOF_INT_P == 4)
170 typedef uint32_t uintptr_t;
171 # else
172 #  if (SIZEOF_INT_P == 8)
173 typedef uint64_t uintptr_t;
174 #  else
175 #   error "Can't find sizeof pointer. Required!"
176 #  endif
177 # endif
178 #endif
179
180 /* Limits for the above types. */
181 #undef INT8_MIN
182 #undef INT8_MAX
183 #undef UINT8_MAX
184 #undef INT16_MIN
185 #undef INT16_MAX
186 #undef UINT16_MAX
187 #undef INT32_MIN
188 #undef INT32_MAX
189 #undef UINT32_MAX
190
191 #define INT8_MIN        (-127-1)
192 #define INT8_MAX        (127)
193 #define UINT8_MAX       (255u)
194 #define INT16_MIN       (-32767-1)
195 #define INT16_MAX       (32767)
196 #define UINT16_MAX      (65535u)
197 #define INT32_MIN       (-2147483647-1)
198 #define INT32_MAX       (2147483647)
199 #define UINT32_MAX      (4294967295u)
200
201 typedef double            float64_t;
202 typedef float             float32_t;
203
204
205 /* Define the uint versions actually used in Bacula */
206 #ifndef uint8_t
207 #define uint8_t u_int8_t
208 #define uint16_t u_int16_t
209 #define uint32_t u_int32_t
210 #define uint64_t u_int64_t
211 #define uintmax_t u_intmax_t
212 #endif
213
214 /* Bacula time -- Unix time with microseconds */
215 #define btime_t int64_t
216 /* Unix time (time_t) widened to 64 bits */
217 #define utime_t int64_t
218
219 #ifndef HAVE_SOCKLEN_T
220 #define socklen_t int
221 #endif
222
223 #ifndef HAVE_WIN32
224 #ifndef SOCKET_ERROR
225 #define SOCKET_ERROR (-1)
226 #endif
227 #endif
228
229 #ifdef HAVE_OLD_SOCKOPT
230 #define sockopt_val_t char *
231 #else
232 #define sockopt_val_t void *
233 #endif
234
235 /*
236  * Status codes returned by create_file()
237  *   Used in findlib, filed, and plugins
238  */
239 enum {
240    CF_SKIP = 1,                   /* skip file (not newer or something) */
241    CF_ERROR,                      /* error creating file */
242    CF_EXTRACT,                    /* file created, data to extract */
243    CF_CREATED,                    /* file created, no data to extract */
244    CF_CORE                        /* let bacula core handle the file creation */
245 };
246
247 #ifndef MAX
248 #define MAX(a, b) ((a) > (b) ? (a) : (b))
249 #endif
250 #ifndef MIN
251 #define MIN(a, b) ((a) < (b) ? (a) : (b))
252 #endif
253
254 #endif /* __bc_types_INCLUDED */