]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/compat/compat.h
Detect the case where logfiles but no databases are being restored.
[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 two of the GNU 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 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 #ifndef INT64
61 #define INT64 long long int
62 #endif
63
64 typedef UINT64 u_int64_t;
65 typedef UINT64 uint64_t;
66 typedef INT64 int64_t;
67 typedef UINT32 uint32_t;
68 typedef INT64 intmax_t;
69 typedef unsigned char uint8_t;
70 typedef unsigned short uint16_t;
71 typedef signed short int16_t;
72 typedef signed char int8_t;
73 typedef int __daddr_t;
74
75 #if !defined(HAVE_MINGW)
76 typedef long int32_t;
77 typedef float float32_t;
78 typedef double float64_t;
79 #endif
80
81 #if !defined(_MSC_VER) || (_MSC_VER < 1400) // VC8+
82 #ifndef _TIME_T_DEFINED
83 #define _TIME_T_DEFINED
84 typedef long time_t;
85 #endif
86 #endif
87
88 #if __STDC__ && !defined(HAVE_MINGW)
89 typedef _dev_t dev_t;
90 #if !defined(HAVE_WXCONSOLE)
91 typedef __int64 ino_t;
92 #endif
93 #endif
94
95 typedef UINT32 u_int32_t;
96 typedef unsigned char u_int8_t;
97 typedef unsigned short u_int16_t;
98
99 #if !defined(HAVE_MINGW)
100 #undef uint32_t
101 #endif
102
103 void sleep(int);
104
105 typedef UINT32 key_t;
106
107 #if defined(HAVE_MINGW)
108 #if !defined(uid_t)
109 typedef UINT32 uid_t;
110 typedef UINT32 gid_t;
111 #endif
112 #else
113 typedef UINT32 uid_t;
114 typedef UINT32 gid_t;
115 typedef UINT32 mode_t;
116 typedef INT32  ssize_t;
117 typedef UINT32 size_t;
118 #define HAVE_SSIZE_T 1
119
120 #endif /* HAVE_MINGW */
121
122 struct dirent {
123     uint64_t    d_ino;
124     uint32_t    d_off;
125     uint16_t    d_reclen;
126     char        d_name[256];
127 };
128 typedef void DIR;
129
130
131 #if !defined(__cplusplus)
132 #if !defined(true)
133 #define true 1
134 #endif
135 #if !defined(false)
136 #define false 0
137 #endif
138 #endif
139
140 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
141 #define _TIMEZONE_DEFINED
142 struct timezone {
143     int foo;
144 };
145 #endif
146
147 int strcasecmp(const char*, const char *);
148 int gettimeofday(struct timeval *, struct timezone *);
149
150 #if !defined(EETXTBUSY)
151 #define EETXTBUSY 26
152 #endif
153
154 #if !defined(ETIMEDOUT)
155 #define ETIMEDOUT 55
156 #endif
157
158 #if !defined(ENOMEDIUM)
159 #define ENOMEDIUM 123
160 #endif
161
162 #if !defined(ENODATA)
163 #define ENODATA 61
164 #endif
165
166 struct stat
167 {
168     _dev_t      st_dev;
169     uint64_t    st_ino;
170     uint16_t    st_mode;
171     int16_t     st_nlink;
172     uint32_t    st_uid;
173     uint32_t    st_gid;
174     _dev_t      st_rdev;
175     uint64_t    st_size;
176     time_t      st_atime;
177     time_t      st_mtime;
178     time_t      st_ctime;
179     uint32_t    st_blksize;
180     uint64_t    st_blocks;
181 };
182
183 #undef  S_IFMT
184 #define S_IFMT         0170000         /* file type mask */
185 #undef  S_IFDIR
186 #define S_IFDIR        0040000         /* directory */
187 #define S_IFCHR        0020000         /* character special */
188 #define S_IFBLK        0060000         /* block special */
189 #define S_IFIFO        0010000         /* pipe */
190 #undef  S_IFREG
191 #define S_IFREG        0100000         /* regular */
192 #define S_IREAD        0000400         /* read permission, owner */
193 #define S_IWRITE       0000200         /* write permission, owner */
194 #define S_IEXEC        0000100         /* execute/search permission, owner */
195
196 #define S_IRUSR         S_IREAD
197 #define S_IWUSR         S_IWRITE
198 #define S_IXUSR         S_IEXEC
199 #define S_ISREG(x)  (((x) & S_IFMT) == S_IFREG)
200 #define S_ISDIR(x)  (((x) & S_IFMT) == S_IFDIR)
201 #define S_ISCHR(x) 0
202 #define S_ISBLK(x)  (((x) & S_IFMT) == S_IFBLK)
203 #define S_ISFIFO(x) 0
204
205 #define S_IRGRP         000040
206 #define S_IWGRP         000020
207 #define S_IXGRP         000010
208
209 #define S_IROTH         00004
210 #define S_IWOTH         00002
211 #define S_IXOTH         00001
212
213 #define S_IRWXO         000007
214 #define S_IRWXG         000070
215 #define S_ISUID         004000
216 #define S_ISGID         002000
217 #define S_ISVTX         001000
218 #define S_ISSOCK(x) 0
219 #define S_ISLNK(x)      0
220
221 #if __STDC__
222 #define O_RDONLY _O_RDONLY
223 #define O_WRONLY _O_WRONLY
224 #define O_RDWR   _O_RDWR
225 #define O_CREAT  _O_CREAT
226 #define O_TRUNC  _O_TRUNC
227
228 #define isascii __isascii
229 #define toascii __toascii
230 #define iscsymf __iscsymf
231 #define iscsym  __iscsym
232 #endif
233
234 typedef  BOOL (*t_pVSSPathConvert)(const char *szFilePath, char *szShadowPath, int nBuflen);
235 typedef  BOOL (*t_pVSSPathConvertW)(const wchar_t  *szFilePath, wchar_t  *szShadowPath, int nBuflen);
236
237 void SetVSSPathConvert(t_pVSSPathConvert pPathConvert, t_pVSSPathConvertW pPathConvertW);
238
239 int lchown(const char *, uid_t uid, gid_t gid);
240 int chown(const char *, uid_t uid, gid_t gid);
241 #if !defined(HAVE_MINGW)
242 int chmod(const char *, mode_t mode);
243 #endif
244 #define O_NONBLOCK   04000
245 #define F_GETFL      3
246 #define F_SETFL      4
247
248 int win32_tape_open(const char *file, int flags, ...);
249 int win32_tape_ioctl(int fd, unsigned long int request, ...);
250 int win32_tape_close(int fd);
251 ssize_t win32_tape_read(int fd, void *buffer, size_t count);
252 ssize_t win32_tape_write(int fd, const void *buffer, size_t count);
253
254 ssize_t win32_read(int fd, void *buffer, size_t count);
255 ssize_t win32_write(int fd, const void *buffer, size_t count);
256 int win32_ioctl(int fd, unsigned long int req, ...);
257
258 #define open   _open
259
260 int fcntl(int fd, int cmd, long arg);
261 int fstat(int fd, struct stat *sb);
262
263 int inet_aton(const char *cp, struct in_addr *inp);
264 int kill(int pid, int signo);
265 int pipe(int []);
266 int fork();
267 int waitpid(int, int *, int);
268
269 #if !defined(HAVE_MINGW)
270 #define strncasecmp strnicmp
271 //int strncasecmp(const char*, const char *, int);
272 int utime(const char *filename, struct utimbuf *buf);
273 #define vsnprintf _vsnprintf
274 #define snprintf _snprintf
275 #endif //HAVE_MINGW
276
277
278 #define WNOHANG 0
279 #define WIFEXITED(x) 0
280 #define WEXITSTATUS(x) x
281 #define WIFSIGNALED(x) 0
282 #define WTERMSIG(x) x
283 #define SIGKILL 9
284 #define SIGUSR2 9999
285
286 #define HAVE_OLD_SOCKOPT
287
288 struct timespec;
289 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
290 int nanosleep(const struct timespec*, struct timespec *);
291 long int random(void);
292 void srandom(unsigned int seed);
293 int lstat(const char *, struct stat *);
294 int stat(const char *file, struct stat *sb);
295 long pathconf(const char *, int);
296 int readlink(const char *, char *, int);
297 #define _PC_PATH_MAX 1
298 #define _PC_NAME_MAX 2
299
300 int geteuid();
301
302 DIR *opendir(const char *name);
303 int closedir(DIR *dir);
304
305 struct passwd {
306     char *foo;
307 };
308
309 struct group {
310     char *foo;
311 };
312
313 struct passwd *getpwuid(uid_t);
314 struct group *getgrgid(uid_t);
315
316 struct sigaction {
317     int sa_flags;
318     void (*sa_handler)(int);
319 };
320 #define sigfillset(x)
321 #define sigaction(a, b, c)
322
323 #define mkdir(p, m) win32_mkdir(p)
324 #define unlink win32_unlink
325 #define chdir win32_chdir
326 #define chmod win32_chmod
327 extern "C" void syslog(int type, const char *fmt, ...);
328 #if !defined(LOG_DAEMON)
329 #define LOG_DAEMON 0
330 #endif
331
332 #if !defined(HAVE_MINGW)
333 #define R_OK 04
334 #define W_OK 02
335 int stat(const char *, struct stat *);
336 #if defined(__cplusplus)
337 #define access _access
338 extern "C" _CRTIMP int __cdecl _access(const char *, int);
339 int execvp(const char *, char *[]);
340 extern "C" void *  __cdecl _alloca(size_t);
341 #endif
342 #endif //HAVE_MINGW
343
344 #define getpid _getpid
345
346 #define getppid() 0
347 #define gethostid() 0
348 #define getuid() 0
349 #define getgid() 0
350
351 #define getcwd win32_getcwd
352 #define chdir win32_chdir
353 #define chmod win32_chmod
354 #define fputs win32_fputs
355 char *win32_getcwd(char *buf, int maxlen);
356 int win32_chdir(const char *buf);
357 int win32_mkdir(const char *buf);
358 int win32_fputs(const char *string, FILE *stream);
359 int win32_unlink(const char *filename);
360 int win32_chmod(const char *, mode_t);
361
362
363 char* win32_cgets (char* buffer, int len);
364
365 int WSA_Init(void);
366 void Win32ConvCleanupCache();
367
368 #if defined(HAVE_MINGW)
369 void closelog();
370 void openlog(const char *ident, int option, int facility);
371 #endif //HAVE_MINGW
372
373 #if !defined(INVALID_FILE_ATTRIBUTES)
374 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
375 #endif
376
377 #if defined(_MSC_VER)
378 inline unsigned long ffs(unsigned long word)
379 {
380    unsigned long  index;
381    
382    if (_BitScanForward(&index, word) != 0)
383       return index + 1;
384    else
385       return 0;
386 }
387
388 #else
389 #define  ffs   __builtin_ffs
390 #endif
391
392
393 int win32_ftruncate(int fd, int64_t length);
394
395 #undef ftruncate
396 #define ftruncate win32_ftruncate
397
398 #endif /* __COMPAT_H_ */