]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/bc_types.h
e55b377bb23d07457463a06dcc87f75b0d4b313c
[bacula/bacula] / bacula / src / bc_types.h
1 /*
2     Integer types.  These types should be be used in all
3     contexts in which the length of an integer stored on
4     removable media must be known regardless of the
5     architecture of the platform.
6
7     Bacula types are:
8
9     int8_t,  int16_t,  int32_t,  int64_t
10     uint8_t, uint16_t, uint32_t, uint64_t
11
12     Also, we define types such as file address lengths.
13
14     Version $Id$
15
16  */
17 /*
18    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
19
20    This program is free software; you can redistribute it and/or
21    modify it under the terms of the GNU General Public License as
22    published by the Free Software Foundation; either version 2 of
23    the License, or (at your option) any later version.
24
25    This program is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28    General Public License for more details.
29
30    You should have received a copy of the GNU General Public
31    License along with this program; if not, write to the Free
32    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33    MA 02111-1307, USA.
34
35  */
36
37
38 #ifndef __bc_types_INCLUDED
39 #define __bc_types_INCLUDED
40
41 typedef char POOLMEM;   
42 #define mp_chr(x) x
43 #ifdef xxxxx
44 #define mp_chr(x) ((char*)(x))
45 struct POOLMEM { 
46    POOLMEM() {}
47    operator const char*() const { return (char *)this; }
48 };
49 #endif
50
51
52 /* Types */
53
54 /* If sys/types.h does not supply intXX_t, supply them ourselves */
55 /* (or die trying) */
56
57 #ifndef HAVE_U_INT
58 typedef unsigned int u_int;
59 #endif
60
61 #ifndef HAVE_INTXX_T
62 # if (SIZEOF_CHAR == 1)
63 typedef char int8_t;
64 # else
65 #  error "8 bit int type not found."
66 # endif
67 # if (SIZEOF_SHORT_INT == 2)
68 typedef short int int16_t;
69 # else
70 #  error "16 bit int type not found."
71 # endif
72 # if (SIZEOF_INT == 4)
73 typedef int int32_t;
74 # else
75 #  error "32 bit int type not found."
76 # endif
77 #endif
78
79 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */
80 #ifndef HAVE_U_INTXX_T
81 # ifdef HAVE_UINTXX_T
82 typedef uint8_t u_int8_t;
83 typedef uint16_t u_int16_t;
84 typedef uint32_t u_int32_t;
85 # define HAVE_U_INTXX_T 1
86 # else
87 #  if (SIZEOF_CHAR == 1)
88 typedef unsigned char u_int8_t;
89 #  else
90 #   error "8 bit int type not found. Required!"
91 #  endif
92 #  if (SIZEOF_SHORT_INT == 2)
93 typedef unsigned short int u_int16_t;
94 #  else
95 #   error "16 bit int type not found. Required!"
96 #  endif
97 #  if (SIZEOF_INT == 4)
98 typedef unsigned int u_int32_t;
99 #  else
100 #   error "32 bit int type not found. Required!"
101 #  endif
102 # endif
103 #endif
104
105 /* 64-bit types */
106 #ifndef HAVE_INT64_T
107 # if (SIZEOF_LONG_LONG_INT == 8)
108 typedef long long int int64_t;
109 #   define HAVE_INT64_T 1
110 # else
111 #  if (SIZEOF_LONG_INT == 8)
112 typedef long int int64_t;
113 #   define HAVE_INT64_T 1
114 #  endif
115 # endif
116 #endif
117
118 #ifndef HAVE_INTMAX_T
119 # ifdef HAVE_INT64_T
120 typedef int64_t intmax_t;
121 # else
122 #   error "64 bit type not found. Required!"
123 # endif
124 #endif
125
126 #ifndef HAVE_U_INT64_T
127 # if (SIZEOF_LONG_LONG_INT == 8)
128 typedef unsigned long long int u_int64_t;
129 #   define HAVE_U_INT64_T 1
130 # else
131 #  if (SIZEOF_LONG_INT == 8)
132 typedef unsigned long int u_int64_t;
133 #   define HAVE_U_INT64_T 1
134 #  else
135 #   error "64 bit type not found. Required!"
136 #  endif
137 # endif
138 #endif
139
140 #ifndef HAVE_U_INTMAX_T
141 # ifdef HAVE_U_INT64_T
142 typedef u_int64_t u_intmax_t;
143 # else
144 #   error "64 bit type not found. Required!"
145 # endif
146 #endif
147
148
149 /* Limits for the above types. */
150 #undef INT8_MIN  
151 #undef INT8_MAX  
152 #undef UINT8_MAX 
153 #undef INT16_MIN 
154 #undef INT16_MAX 
155 #undef UINT16_MAX
156 #undef INT32_MIN 
157 #undef INT32_MAX 
158 #undef UINT32_MAX
159
160 #define INT8_MIN        (-127-1)
161 #define INT8_MAX        (127)
162 #define UINT8_MAX       (255u)
163 #define INT16_MIN       (-32767-1)
164 #define INT16_MAX       (32767)
165 #define UINT16_MAX      (65535u)
166 #define INT32_MIN       (-2147483647-1)
167 #define INT32_MAX       (2147483647)
168 #define UINT32_MAX      (4294967295u)
169
170 typedef double            float64_t;
171 typedef float             float32_t;
172
173 #endif /* __bc_types_INCLUDED */
174
175 /* Define the uint versions actually used in Bacula */
176 #define uint8_t u_int8_t
177 #define uint16_t u_int16_t
178 #define uint32_t u_int32_t
179 #define uint64_t u_int64_t
180 #define uintmax_t u_intmax_t
181
182 /* Bacula time -- Unix time with microseconds */
183 #define btime_t uint64_t
184 /* Unix time (time_t) widened to 64 bits */
185 #define utime_t int64_t
186
187 #ifdef HAVE_CYGWIN
188 #define int_least16_t int32_t
189 #endif
190
191 #ifndef HAVE_SOCKLEN_T
192 #define socklen_t int
193 #endif
194
195 #ifdef HAVE_OLD_SOCKOPT
196 #define sockopt_val_t char *
197 #else
198 #define sockopt_val_t void *
199 #endif