]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/compat/compat.h
Fix QT tray monitor compilation on windows
[bacula/bacula] / bacula / src / win32 / compat / compat.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2011 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  */
38
39
40 #if !defined(__COMPAT_H_)
41 #define __COMPAT_H_
42 #if !defined(_STAT_H)
43 #define _STAT_H         /* don't pull in MinGW stat.h */
44 #endif
45
46 #ifndef _STAT_DEFINED
47 #define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
48 #endif
49
50 #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC8+
51 #pragma warning(disable : 4996) // Either disable all deprecation warnings,
52 // #define _CRT_SECURE_NO_DEPRECATE // Or just turn off warnings about the newly deprecated CRT functions.
53 #elif !defined(HAVE_MINGW) && !defined(HAVE_WXCONSOLE)
54 #define __STDC__ 1
55 #endif
56
57 #include <malloc.h>
58
59 #ifdef MINGW64
60 #include <direct.h>
61 #define _declspec __declspec
62
63 /* Missing in 64 bit mingw */
64 typedef struct _REPARSE_DATA_BUFFER {
65         DWORD  ReparseTag;
66         WORD   ReparseDataLength;
67         WORD   Reserved;
68         union {
69                 struct {
70                         WORD   SubstituteNameOffset;
71                         WORD   SubstituteNameLength;
72                         WORD   PrintNameOffset;
73                         WORD   PrintNameLength;
74                         WCHAR PathBuffer[1];
75                 } SymbolicLinkReparseBuffer;
76                 struct {
77                         WORD   SubstituteNameOffset;
78                         WORD   SubstituteNameLength;
79                         WORD   PrintNameOffset;
80                         WORD   PrintNameLength;
81                         WCHAR PathBuffer[1];
82                 } MountPointReparseBuffer;
83                 struct {
84                         BYTE   DataBuffer[1];
85                 } GenericReparseBuffer;
86         } DUMMYUNIONNAME;
87 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
88
89 #endif
90
91 #include <winioctl.h>
92
93 #ifdef _WIN64
94 # define GWL_USERDATA  GWLP_USERDATA
95 #endif
96
97 #ifndef INT64
98 #define INT64 long long int
99 #endif
100
101 typedef UINT64 u_int64_t;
102 typedef UINT64 uint64_t;
103 typedef INT64 int64_t;
104 typedef UINT32 uint32_t;
105 typedef INT64 intmax_t;
106 typedef unsigned char uint8_t;
107 typedef unsigned short uint16_t;
108 typedef signed short int16_t;
109 typedef signed char int8_t;
110 typedef int __daddr_t;
111
112 #if !defined(HAVE_MINGW)
113 typedef long int32_t;
114 typedef float float32_t;
115 typedef double float64_t;
116 #endif
117
118 #if !defined(_MSC_VER) || (_MSC_VER < 1400) // VC8+
119 #ifndef _TIME_T_DEFINED
120 #define _TIME_T_DEFINED
121 typedef long time_t;
122 #endif
123 #endif
124
125 #if __STDC__ && !defined(HAVE_MINGW)
126 typedef _dev_t dev_t;
127 #if !defined(HAVE_WXCONSOLE)
128 typedef __int64 ino_t;
129 #endif
130 #endif
131
132 typedef UINT32 u_int32_t;
133 typedef unsigned char u_int8_t;
134 typedef unsigned short u_int16_t;
135
136 #if !defined(HAVE_MINGW)
137 #undef uint32_t
138 #endif
139
140 void sleep(int);
141
142 typedef UINT32 key_t;
143
144 #if defined(HAVE_MINGW)
145 #if !defined(uid_t)
146 typedef UINT32 uid_t;
147 typedef UINT32 gid_t;
148 #endif
149 #else
150 typedef UINT32 uid_t;
151 typedef UINT32 gid_t;
152 typedef UINT32 mode_t;
153 typedef INT32  ssize_t;
154 typedef UINT32 size_t;
155 #define HAVE_SSIZE_T 1
156
157 #endif /* HAVE_MINGW */
158
159 struct dirent {
160     uint64_t    d_ino;
161     uint32_t    d_off;
162     uint16_t    d_reclen;
163     char        d_name[256];
164 };
165 typedef void DIR;
166
167
168 #if !defined(__cplusplus)
169 #if !defined(true)
170 #define true 1
171 #endif
172 #if !defined(false)
173 #define false 0
174 #endif
175 #endif
176
177 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
178 #define _TIMEZONE_DEFINED
179 struct timezone {
180     int foo;
181 };
182 #endif
183
184 int strcasecmp(const char*, const char *);
185 int gettimeofday(struct timeval *, struct timezone *);
186
187 #if !defined(EETXTBUSY)
188 #define EETXTBUSY 26
189 #endif
190
191 #if !defined(ETIMEDOUT)
192 #define ETIMEDOUT 55
193 #endif
194
195 #if !defined(ENOMEDIUM)
196 #define ENOMEDIUM 123
197 #endif
198
199 #if !defined(ENODATA)
200 #define ENODATA 61
201 #endif
202
203 struct stat
204 {
205     _dev_t      st_dev;
206     uint64_t    st_ino;
207     uint16_t    st_mode;
208     int16_t     st_nlink;
209     uint32_t    st_uid;
210     uint32_t    st_gid;
211     _dev_t      st_rdev;
212     uint64_t    st_size;
213     time_t      st_atime;
214     time_t      st_mtime;
215     time_t      st_ctime;
216     uint32_t    st_blksize;
217     uint64_t    st_blocks;
218 };
219
220 #undef  S_IFMT
221 #define S_IFMT         0170000         /* file type mask */
222 #undef  S_IFDIR
223 #define S_IFDIR        0040000         /* directory */
224 #define S_IFCHR        0020000         /* character special */
225 #define S_IFBLK        0060000         /* block special */
226 #define S_IFIFO        0010000         /* pipe */
227 #undef  S_IFREG
228 #define S_IFREG        0100000         /* regular */
229 #define S_IREAD        0000400         /* read permission, owner */
230 #define S_IWRITE       0000200         /* write permission, owner */
231 #define S_IEXEC        0000100         /* execute/search permission, owner */
232
233 #define S_IRUSR         S_IREAD
234 #define S_IWUSR         S_IWRITE
235 #define S_IXUSR         S_IEXEC
236 #define S_ISREG(x)  (((x) & S_IFMT) == S_IFREG)
237 #define S_ISDIR(x)  (((x) & S_IFMT) == S_IFDIR)
238 #define S_ISCHR(x) 0
239 #define S_ISBLK(x)  (((x) & S_IFMT) == S_IFBLK)
240 #define S_ISFIFO(x) 0
241
242 #define S_IRGRP         000040
243 #define S_IWGRP         000020
244 #define S_IXGRP         000010
245
246 #define S_IROTH         00004
247 #define S_IWOTH         00002
248 #define S_IXOTH         00001
249
250 #define S_IRWXO         000007
251 #define S_IRWXG         000070
252 #define S_ISUID         004000
253 #define S_ISGID         002000
254 #define S_ISVTX         001000
255 #define S_ISSOCK(x) 0
256 #define S_ISLNK(x)      0
257
258 #if __STDC__
259 #define O_RDONLY _O_RDONLY
260 #define O_WRONLY _O_WRONLY
261 #define O_RDWR   _O_RDWR
262 #define O_CREAT  _O_CREAT
263 #define O_TRUNC  _O_TRUNC
264
265 #define isascii __isascii
266 #define toascii __toascii
267 #define iscsymf __iscsymf
268 #define iscsym  __iscsym
269 #endif
270
271 typedef  BOOL (*t_pVSSPathConvert)(const char *szFilePath, char *szShadowPath, int nBuflen);
272 typedef  BOOL (*t_pVSSPathConvertW)(const wchar_t  *szFilePath, wchar_t  *szShadowPath, int nBuflen);
273
274 void SetVSSPathConvert(t_pVSSPathConvert pPathConvert, t_pVSSPathConvertW pPathConvertW);
275
276 int lchown(const char *, uid_t uid, gid_t gid);
277 int chown(const char *, uid_t uid, gid_t gid);
278 #if !defined(HAVE_MINGW)
279 int chmod(const char *, mode_t mode);
280 #endif
281 #define O_NONBLOCK   04000
282 #define F_GETFL      3
283 #define F_SETFL      4
284
285 int win32_tape_open(const char *file, int flags, ...);
286 int win32_tape_ioctl(int fd, unsigned long int request, ...);
287 int win32_tape_close(int fd);
288 ssize_t win32_tape_read(int fd, void *buffer, size_t count);
289 ssize_t win32_tape_write(int fd, const void *buffer, size_t count);
290
291 ssize_t win32_read(int fd, void *buffer, size_t count);
292 ssize_t win32_write(int fd, const void *buffer, size_t count);
293 int win32_ioctl(int fd, unsigned long int req, ...);
294
295 #ifndef MINGW64
296 #define open   _open
297 #endif
298
299 int fcntl(int fd, int cmd, long arg);
300 int fstat(intptr_t fd, struct stat *sb);
301
302 int inet_aton(const char *cp, struct in_addr *inp);
303 int kill(int pid, int signo);
304 int pipe(int []);
305 int fork();
306 int waitpid(int, int *, int);
307
308 #if !defined(HAVE_MINGW)
309 #define strncasecmp strnicmp
310 //int strncasecmp(const char*, const char *, int);
311 int utime(const char *filename, struct utimbuf *buf);
312 #define vsnprintf _vsnprintf
313 #define snprintf _snprintf
314 #endif //HAVE_MINGW
315
316
317 #define WNOHANG 0
318 #define WIFEXITED(x) 0
319 #define WEXITSTATUS(x) x
320 #define WIFSIGNALED(x) 0
321 #define WTERMSIG(x) x
322 #define SIGKILL 9
323 #define SIGUSR2 9999
324
325 #define HAVE_OLD_SOCKOPT
326
327 struct timespec;
328 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
329 int nanosleep(const struct timespec*, struct timespec *);
330 long int random(void);
331 void srandom(unsigned int seed);
332 int lstat(const char *, struct stat *);
333 int stat(const char *file, struct stat *sb);
334 long pathconf(const char *, int);
335 int readlink(const char *, char *, int);
336 #define _PC_PATH_MAX 1
337 #define _PC_NAME_MAX 2
338
339 int geteuid();
340
341 DIR *opendir(const char *name);
342 int closedir(DIR *dir);
343
344 struct passwd {
345     char *foo;
346 };
347
348 struct group {
349     char *foo;
350 };
351
352 struct passwd *getpwuid(uid_t);
353 struct group *getgrgid(uid_t);
354
355 struct sigaction {
356     int sa_flags;
357     void (*sa_handler)(int);
358 };
359 #define sigfillset(x)
360 #define sigaction(a, b, c)
361
362 #define mkdir(p, m) win32_mkdir(p)
363 #define unlink win32_unlink
364 #define chdir win32_chdir
365 #define chmod win32_chmod
366 extern "C" void syslog(int type, const char *fmt, ...);
367 #if !defined(LOG_DAEMON)
368 #define LOG_DAEMON 0
369 #endif
370
371 #if !defined(HAVE_MINGW)
372 #define R_OK 04
373 #define W_OK 02
374 int stat(const char *, struct stat *);
375 #if defined(__cplusplus)
376 #define access _access
377 extern "C" _CRTIMP int __cdecl _access(const char *, int);
378 int execvp(const char *, char *[]);
379 extern "C" void *  __cdecl _alloca(size_t);
380 #endif
381 #endif //HAVE_MINGW
382
383 #define getpid _getpid
384
385 #define getppid() 0
386 #define gethostid() 0
387 #define getuid() 0
388 #define getgid() 0
389
390 #define getcwd win32_getcwd
391 #define chdir win32_chdir
392 #define chmod win32_chmod
393 #define fputs win32_fputs
394 char *win32_getcwd(char *buf, int maxlen);
395 int win32_chdir(const char *buf);
396 int win32_mkdir(const char *buf);
397 int win32_fputs(const char *string, FILE *stream);
398 int win32_unlink(const char *filename);
399 int win32_chmod(const char *, mode_t);
400
401
402 char* win32_cgets (char* buffer, int len);
403
404 int WSA_Init(void);
405 void Win32ConvCleanupCache();
406
407 #if defined(HAVE_MINGW)
408 void closelog();
409 void openlog(const char *ident, int option, int facility);
410 #endif //HAVE_MINGW
411
412 /* Don't let OS go to sleep (usually a Laptop) while we are backing up */
413 void prevent_os_suspensions();
414 void allow_os_suspensions();
415
416 typedef DWORD EXECUTION_STATE;
417 #ifndef ES_CONTINUOUS
418 #define ES_CONTINUOUS            0x80000000
419 #endif
420 #ifndef ES_SYSTEM_REQUIRED
421 #define ES_SYSTEM_REQUIRED       0x00000001
422 #endif
423 #ifndef ES_DISPLAY_REQUIRED
424 #define ES_DISPLAY_REQUIRED      0x00000002
425 #endif
426 #ifndef ES_USER_PRESENT
427 # define ES_USER_PRESENT          0x00000004
428 #endif
429
430 WINBASEAPI EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE esFlags);
431
432
433 extern void LogErrorMsg(const char *message);
434
435 #if !defined(INVALID_FILE_ATTRIBUTES)
436 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
437 #endif
438
439 #if defined(_MSC_VER)
440 inline unsigned long ffs(unsigned long word)
441 {
442    unsigned long  index;
443    
444    if (_BitScanForward(&index, word) != 0)
445       return index + 1;
446    else
447       return 0;
448 }
449
450 #else
451 #define  ffs   __builtin_ffs
452 #endif
453
454
455 int win32_ftruncate(int fd, int64_t length);
456
457 #undef ftruncate
458 #define ftruncate win32_ftruncate
459
460 #endif /* __COMPAT_H_ */