]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/compat/compat.h
Fix some double Win32 #ifdefs
[bacula/bacula] / bacula / src / win32 / compat / compat.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*                               -*- Mode: C -*-
29  * compat.h --
30  */
31 // Copyright transferred from Raider Solutions, Inc to
32 //   Kern Sibbald and John Walker by express permission.
33 //
34 /*
35  * Author          : Christopher S. Hull
36  * Created On      : Fri Jan 30 13:00:51 2004
37  * Last Modified By: Thorsten Engel
38  * Last Modified On: Fri Apr 22 19:30:00 2004
39  * Update Count    : 218
40  * $Id$
41  */
42
43
44 #if !defined(__COMPAT_H_)
45 #define __COMPAT_H_
46 #if !defined(_STAT_H)
47 #define _STAT_H       /* don't pull in MinGW stat.h */
48 #define _STAT_DEFINED /* don't pull in MinGW stat.h */
49 #endif
50
51 #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC8+
52 #pragma warning(disable : 4996) // Either disable all deprecation warnings,
53 // #define _CRT_SECURE_NO_DEPRECATE // Or just turn off warnings about the newly deprecated CRT functions.
54 #elif !defined(HAVE_MINGW) && !defined(HAVE_WXCONSOLE)
55 #define __STDC__ 1
56 #endif
57
58 #include <malloc.h>
59
60 #ifdef MINGW64
61 #include <direct.h>
62 #define _declspec __declspec
63 #endif
64
65 #ifdef _WIN64
66 # define GWL_USERDATA  GWLP_USERDATA
67 #endif
68
69 #ifndef INT64
70 #define INT64 long long int
71 #endif
72
73 typedef UINT64 u_int64_t;
74 typedef UINT64 uint64_t;
75 typedef INT64 int64_t;
76 typedef UINT32 uint32_t;
77 typedef INT64 intmax_t;
78 typedef unsigned char uint8_t;
79 typedef unsigned short uint16_t;
80 typedef signed short int16_t;
81 typedef signed char int8_t;
82 typedef int __daddr_t;
83
84 #if !defined(HAVE_MINGW)
85 typedef long int32_t;
86 typedef float float32_t;
87 typedef double float64_t;
88 #endif
89
90 #if !defined(_MSC_VER) || (_MSC_VER < 1400) // VC8+
91 #ifndef _TIME_T_DEFINED
92 #define _TIME_T_DEFINED
93 typedef long time_t;
94 #endif
95 #endif
96
97 #if __STDC__ && !defined(HAVE_MINGW)
98 typedef _dev_t dev_t;
99 #if !defined(HAVE_WXCONSOLE)
100 typedef __int64 ino_t;
101 #endif
102 #endif
103
104 typedef UINT32 u_int32_t;
105 typedef unsigned char u_int8_t;
106 typedef unsigned short u_int16_t;
107
108 #if !defined(HAVE_MINGW)
109 #undef uint32_t
110 #endif
111
112 void sleep(int);
113
114 typedef UINT32 key_t;
115
116 #if defined(HAVE_MINGW)
117 #if !defined(uid_t)
118 typedef UINT32 uid_t;
119 typedef UINT32 gid_t;
120 #endif
121 #else
122 typedef UINT32 uid_t;
123 typedef UINT32 gid_t;
124 typedef UINT32 mode_t;
125 typedef INT32  ssize_t;
126 typedef UINT32 size_t;
127 #define HAVE_SSIZE_T 1
128
129 #endif /* HAVE_MINGW */
130
131 struct dirent {
132     uint64_t    d_ino;
133     uint32_t    d_off;
134     uint16_t    d_reclen;
135     char        d_name[256];
136 };
137 typedef void DIR;
138
139
140 #if !defined(__cplusplus)
141 #if !defined(true)
142 #define true 1
143 #endif
144 #if !defined(false)
145 #define false 0
146 #endif
147 #endif
148
149 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
150 #define _TIMEZONE_DEFINED
151 struct timezone {
152     int foo;
153 };
154 #endif
155
156 int strcasecmp(const char*, const char *);
157 int gettimeofday(struct timeval *, struct timezone *);
158
159 #if !defined(EETXTBUSY)
160 #define EETXTBUSY 26
161 #endif
162
163 #if !defined(ETIMEDOUT)
164 #define ETIMEDOUT 55
165 #endif
166
167 #if !defined(ENOMEDIUM)
168 #define ENOMEDIUM 123
169 #endif
170
171 #if !defined(ENODATA)
172 #define ENODATA 61
173 #endif
174
175 struct stat
176 {
177     _dev_t      st_dev;
178     uint64_t    st_ino;
179     uint16_t    st_mode;
180     int16_t     st_nlink;
181     uint32_t    st_uid;
182     uint32_t    st_gid;
183     _dev_t      st_rdev;
184     uint64_t    st_size;
185     time_t      st_atime;
186     time_t      st_mtime;
187     time_t      st_ctime;
188     uint32_t    st_blksize;
189     uint64_t    st_blocks;
190 };
191
192 #undef  S_IFMT
193 #define S_IFMT         0170000         /* file type mask */
194 #undef  S_IFDIR
195 #define S_IFDIR        0040000         /* directory */
196 #define S_IFCHR        0020000         /* character special */
197 #define S_IFBLK        0060000         /* block special */
198 #define S_IFIFO        0010000         /* pipe */
199 #undef  S_IFREG
200 #define S_IFREG        0100000         /* regular */
201 #define S_IREAD        0000400         /* read permission, owner */
202 #define S_IWRITE       0000200         /* write permission, owner */
203 #define S_IEXEC        0000100         /* execute/search permission, owner */
204
205 #define S_IRUSR         S_IREAD
206 #define S_IWUSR         S_IWRITE
207 #define S_IXUSR         S_IEXEC
208 #define S_ISREG(x)  (((x) & S_IFMT) == S_IFREG)
209 #define S_ISDIR(x)  (((x) & S_IFMT) == S_IFDIR)
210 #define S_ISCHR(x) 0
211 #define S_ISBLK(x)  (((x) & S_IFMT) == S_IFBLK)
212 #define S_ISFIFO(x) 0
213
214 #define S_IRGRP         000040
215 #define S_IWGRP         000020
216 #define S_IXGRP         000010
217
218 #define S_IROTH         00004
219 #define S_IWOTH         00002
220 #define S_IXOTH         00001
221
222 #define S_IRWXO         000007
223 #define S_IRWXG         000070
224 #define S_ISUID         004000
225 #define S_ISGID         002000
226 #define S_ISVTX         001000
227 #define S_ISSOCK(x) 0
228 #define S_ISLNK(x)      0
229
230 #if __STDC__
231 #define O_RDONLY _O_RDONLY
232 #define O_WRONLY _O_WRONLY
233 #define O_RDWR   _O_RDWR
234 #define O_CREAT  _O_CREAT
235 #define O_TRUNC  _O_TRUNC
236
237 #define isascii __isascii
238 #define toascii __toascii
239 #define iscsymf __iscsymf
240 #define iscsym  __iscsym
241 #endif
242
243 typedef  BOOL (*t_pVSSPathConvert)(const char *szFilePath, char *szShadowPath, int nBuflen);
244 typedef  BOOL (*t_pVSSPathConvertW)(const wchar_t  *szFilePath, wchar_t  *szShadowPath, int nBuflen);
245
246 void SetVSSPathConvert(t_pVSSPathConvert pPathConvert, t_pVSSPathConvertW pPathConvertW);
247
248 int lchown(const char *, uid_t uid, gid_t gid);
249 int chown(const char *, uid_t uid, gid_t gid);
250 #if !defined(HAVE_MINGW)
251 int chmod(const char *, mode_t mode);
252 #endif
253 #define O_NONBLOCK   04000
254 #define F_GETFL      3
255 #define F_SETFL      4
256
257 int win32_tape_open(const char *file, int flags, ...);
258 int win32_tape_ioctl(int fd, unsigned long int request, ...);
259 int win32_tape_close(int fd);
260 ssize_t win32_tape_read(int fd, void *buffer, size_t count);
261 ssize_t win32_tape_write(int fd, const void *buffer, size_t count);
262
263 ssize_t win32_read(int fd, void *buffer, size_t count);
264 ssize_t win32_write(int fd, const void *buffer, size_t count);
265 int win32_ioctl(int fd, unsigned long int req, ...);
266
267 #ifndef MINGW64
268 #define open   _open
269 #endif
270
271 int fcntl(int fd, int cmd, long arg);
272 int fstat(intptr_t fd, struct stat *sb);
273
274 int inet_aton(const char *cp, struct in_addr *inp);
275 int kill(int pid, int signo);
276 int pipe(int []);
277 int fork();
278 int waitpid(int, int *, int);
279
280 #if !defined(HAVE_MINGW)
281 #define strncasecmp strnicmp
282 //int strncasecmp(const char*, const char *, int);
283 int utime(const char *filename, struct utimbuf *buf);
284 #define vsnprintf _vsnprintf
285 #define snprintf _snprintf
286 #endif //HAVE_MINGW
287
288
289 #define WNOHANG 0
290 #define WIFEXITED(x) 0
291 #define WEXITSTATUS(x) x
292 #define WIFSIGNALED(x) 0
293 #define WTERMSIG(x) x
294 #define SIGKILL 9
295 #define SIGUSR2 9999
296
297 #define HAVE_OLD_SOCKOPT
298
299 struct timespec;
300 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
301 int nanosleep(const struct timespec*, struct timespec *);
302 long int random(void);
303 void srandom(unsigned int seed);
304 int lstat(const char *, struct stat *);
305 int stat(const char *file, struct stat *sb);
306 long pathconf(const char *, int);
307 int readlink(const char *, char *, int);
308 #define _PC_PATH_MAX 1
309 #define _PC_NAME_MAX 2
310
311 int geteuid();
312
313 DIR *opendir(const char *name);
314 int closedir(DIR *dir);
315
316 struct passwd {
317     char *foo;
318 };
319
320 struct group {
321     char *foo;
322 };
323
324 struct passwd *getpwuid(uid_t);
325 struct group *getgrgid(uid_t);
326
327 struct sigaction {
328     int sa_flags;
329     void (*sa_handler)(int);
330 };
331 #define sigfillset(x)
332 #define sigaction(a, b, c)
333
334 #define mkdir(p, m) win32_mkdir(p)
335 #define unlink win32_unlink
336 #define chdir win32_chdir
337 #define chmod win32_chmod
338 extern "C" void syslog(int type, const char *fmt, ...);
339 #if !defined(LOG_DAEMON)
340 #define LOG_DAEMON 0
341 #endif
342
343 #if !defined(HAVE_MINGW)
344 #define R_OK 04
345 #define W_OK 02
346 int stat(const char *, struct stat *);
347 #if defined(__cplusplus)
348 #define access _access
349 extern "C" _CRTIMP int __cdecl _access(const char *, int);
350 int execvp(const char *, char *[]);
351 extern "C" void *  __cdecl _alloca(size_t);
352 #endif
353 #endif //HAVE_MINGW
354
355 #define getpid _getpid
356
357 #define getppid() 0
358 #define gethostid() 0
359 #define getuid() 0
360 #define getgid() 0
361
362 #define getcwd win32_getcwd
363 #define chdir win32_chdir
364 #define chmod win32_chmod
365 #define fputs win32_fputs
366 char *win32_getcwd(char *buf, int maxlen);
367 int win32_chdir(const char *buf);
368 int win32_mkdir(const char *buf);
369 int win32_fputs(const char *string, FILE *stream);
370 int win32_unlink(const char *filename);
371 int win32_chmod(const char *, mode_t);
372
373
374 char* win32_cgets (char* buffer, int len);
375
376 int WSA_Init(void);
377 void Win32ConvCleanupCache();
378
379 #if defined(HAVE_MINGW)
380 void closelog();
381 void openlog(const char *ident, int option, int facility);
382 #endif //HAVE_MINGW
383
384 void LogErrorMsg(const char *message);
385
386 /* Don't let OS go to sleep (usually a Laptop) while we are backing up */
387 void prevent_os_suspensions();
388 void allow_os_suspensions();
389
390 typedef DWORD EXECUTION_STATE;
391 #ifndef ES_CONTINUOUS
392 #define ES_CONTINUOUS            0x80000000
393 #define ES_SYSTEM_REQUIRED       0x00000001
394 #define ES_DISPLAY_REQUIRED      0x00000002
395 #endif
396 #ifndef ES_USER_PRESENT
397 # define ES_USER_PRESENT          0x00000004
398 #endif
399
400 WINBASEAPI EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE esFlags);
401
402
403 #if !defined(INVALID_FILE_ATTRIBUTES)
404 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
405 #endif
406
407 #if defined(_MSC_VER)
408 inline unsigned long ffs(unsigned long word)
409 {
410    unsigned long  index;
411    
412    if (_BitScanForward(&index, word) != 0)
413       return index + 1;
414    else
415       return 0;
416 }
417
418 #else
419 #define  ffs   __builtin_ffs
420 #endif
421
422
423 int win32_ftruncate(int fd, int64_t length);
424
425 #undef ftruncate
426 #define ftruncate win32_ftruncate
427
428 #endif /* __COMPAT_H_ */