]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/compat/compat.h
added VSS toggling by enable_vss
[bacula/bacula] / bacula / src / win32 / compat / compat.h
1 /*                               -*- Mode: C -*-
2  * compat.h --
3  */
4 // Copyright transferred from Raider Solutions, Inc to
5 //   Kern Sibbald and John Walker by express permission.
6 //
7 // Copyright (C) 2004-2005 Kern Sibbald
8 //
9 //   This program is free software; you can redistribute it and/or
10 //   modify it under the terms of the GNU General Public License as
11 //   published by the Free Software Foundation; either version 2 of
12 //   the License, or (at your option) any later version.
13 //
14 //   This program is distributed in the hope that it will be useful,
15 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 //   General Public License for more details.
18 //
19 //   You should have received a copy of the GNU General Public
20 //   License along with this program; if not, write to the Free
21 //   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 //   MA 02111-1307, USA.
23 /*
24  *
25  * Author          : Christopher S. Hull
26  * Created On      : Fri Jan 30 13:00:51 2004
27  * Last Modified By: Thorsten Engel
28  * Last Modified On: Fri Apr 22 19:30:00 2004
29  * Update Count    : 218
30  * $Id$
31  */
32
33
34 #ifndef __COMPAT_H_
35 #define __COMPAT_H_
36
37 #ifndef HAVE_MINGW
38 #ifndef HAVE_WXCONSOLE
39 #define __STDC__ 1
40 #endif
41 #endif
42
43 #include <stdio.h>
44 #include <basetsd.h>
45 #include <stdarg.h>
46 #include <sys/types.h>
47 #include <process.h>
48 #include <direct.h>
49 #include <winsock2.h>
50 #include <windows.h>
51 #include <wincon.h>
52 #include <winbase.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <stdarg.h>
56 #include <conio.h>
57 #include <process.h>
58 #include <errno.h>
59 #include <string.h>
60 #include <time.h>
61 #include <signal.h>
62 #include <malloc.h>
63 #include <setjmp.h>
64 #include <direct.h>
65 #include <ctype.h>
66 #include <fcntl.h>
67 #include <io.h>
68
69 #if defined HAVE_MINGW
70 #include <stdint.h>
71 #include <sys/stat.h>
72 #endif
73
74 #include "getopt.h"
75
76 #define HAVE_WIN32 1
77
78 #ifndef HAVE_MINGW
79 #ifdef HAVE_CYGWIN
80 #error should not be used under cygwin...
81 #else
82 #endif //HAVE_CYGWIN
83 #endif //HAVE_MINGW
84
85 typedef UINT64 u_int64_t;
86 typedef UINT64 uint64_t;
87 typedef INT64 int64_t;
88 typedef UINT32 uint32_t;
89 typedef long int32_t;
90 typedef INT64 intmax_t;
91 typedef unsigned char uint8_t;
92 typedef float float32_t;
93 typedef unsigned short uint16_t;
94 typedef signed short int16_t;
95 typedef long time_t;
96 typedef signed char int8_t;
97
98 #if __STDC__
99 #ifndef HAVE_MINGW
100 typedef _dev_t dev_t;
101 #ifndef HAVE_WXCONSOLE
102 typedef __int64 ino_t;
103 typedef __int64 off_t;          /* STDC=1 means we can define this */
104 #endif
105 #endif
106 #else
107 typedef long _off_t;            /* must be same as sys/types.h */
108 #endif
109
110 #ifndef HAVE_MINGW
111 #ifndef HAVE_WXCONSOLE
112 typedef int BOOL;
113 #define bool BOOL
114 #endif
115 #endif
116
117 typedef double float64_t;
118 typedef UINT32 u_int32_t;
119 typedef unsigned char u_int8_t;
120 typedef unsigned short u_int16_t;
121
122 #ifndef HAVE_MINGW
123 #undef uint32_t
124 #endif
125
126 void sleep(int);
127
128 typedef UINT32 key_t;
129
130 #ifdef HAVE_MINGW
131 #ifndef uid_t
132 typedef UINT32 uid_t;
133 typedef UINT32 gid_t;
134 #endif
135 #else
136 typedef UINT32 uid_t;
137 typedef UINT32 gid_t;
138 typedef UINT32 mode_t;
139 typedef INT64  ssize_t;
140 #endif //HAVE_MINGW
141
142 struct dirent {
143     uint64_t    d_ino;
144     uint32_t    d_off;
145     uint16_t    d_reclen;
146     char        d_name[256];
147 };
148
149 typedef void DIR;
150
151 #ifndef __cplusplus
152 #ifndef true
153 #define true 1
154 #endif
155 #ifndef false
156 #define false 0
157 #endif
158 #endif
159
160 struct timezone {
161     int foo;
162 };
163
164 int strcasecmp(const char*, const char *);
165 int strncasecmp(const char*, const char *, int);
166 int gettimeofday(struct timeval *, struct timezone *);
167
168 #define ETIMEDOUT 55
169
170 #ifndef HAVE_MINGW
171
172 #ifndef _STAT_DEFINED
173 struct stat
174 {
175     _dev_t      st_dev;
176     uint64_t    st_ino;
177     uint16_t    st_mode;
178     int16_t     st_nlink;
179     uint32_t    st_uid;
180     uint32_t    st_gid;
181     _dev_t      st_rdev;
182     uint64_t    st_size;
183     time_t      st_atime;
184     time_t      st_mtime;
185     time_t      st_ctime;
186     uint32_t    st_blksize;
187     uint64_t    st_blocks;
188 };
189 #endif
190
191 #undef  S_IFMT
192 #define S_IFMT         0170000         /* file type mask */
193 #undef  S_IFDIR
194 #define S_IFDIR        0040000         /* directory */
195 #define S_IFCHR        0020000         /* character special */
196 #define S_IFIFO        0010000         /* pipe */
197 #undef  S_IFREG
198 #define S_IFREG        0100000         /* regular */
199 #define S_IREAD        0000400         /* read permission, owner */
200 #define S_IWRITE       0000200         /* write permission, owner */
201 #define S_IEXEC        0000100         /* execute/search permission, owner */
202
203 #define S_IRUSR         S_IREAD
204 #define S_IWUSR         S_IWRITE
205 #define S_IXUSR         S_IEXEC
206 #define S_ISREG(x)  (((x) & S_IFREG) == S_IFREG)
207 #define S_ISDIR(x)  (((x) & S_IFDIR) == S_IFDIR)
208 #define S_ISCHR(x) 0
209 #define S_ISBLK(x) 0
210 #define S_ISFIFO(x) 0
211 #endif //HAVE_MINGW
212
213 #define S_IRGRP         000040
214 #define S_IWGRP         000020
215 #define S_IXGRP         000010
216
217 #define S_IROTH         00004
218 #define S_IWOTH         00002
219 #define S_IXOTH         00001
220
221 #define S_IRWXO         000007
222 #define S_IRWXG         000070
223 #define S_ISUID         004000
224 #define S_ISGID         002000
225 #define S_ISVTX         001000
226 #define S_ISSOCK(x) 0
227 #define S_ISLNK(x)      0
228
229 #if __STDC__
230 #define O_RDONLY _O_RDONLY
231 #define O_WRONLY _O_WRONLY
232 #define O_RDWR   _O_RDWR
233 #define O_CREAT  _O_CREAT
234 #define O_TRUNC  _O_TRUNC
235
236 #define isascii __isascii
237 #define toascii __toascii
238 #define iscsymf __iscsymf
239 #define iscsym  __iscsym
240 #endif
241
242
243 int umask(int);
244 int lchown(const char *, uid_t uid, gid_t gid);
245 int chown(const char *, uid_t uid, gid_t gid);
246 int chmod(const char *, mode_t mode);
247 off_t lseek(int, off_t, int);
248 int inet_aton(const char *cp, struct in_addr *inp);
249 int kill(int pid, int signo);
250 int pipe(int []);
251 int fork();
252 int dup2(int, int);
253 int waitpid(int, int *, int);
254
255 #ifndef HAVE_MINGW
256 int utime(const char *filename, struct utimbuf *buf);
257 int open(const char *, int, int);
258 #define vsnprintf __vsnprintf
259 int __vsnprintf(char *s, size_t count, const char *format, va_list args);
260
261 #define vsprintf __vsprintf
262 int __vsprintf(char *s, const char *format, va_list args);
263
264 #define snprintf __snprintf
265 int __snprintf(char *str, size_t count, const char *fmt, ...);
266
267 #define sprintf __sprintf
268 int __sprintf(char *str, const char *fmt, ...);
269
270 #ifndef HAVE_WXCONSOLE
271 ssize_t read(int fd, void *, ssize_t nbytes);
272 ssize_t write(int fd, const void *, ssize_t nbytes);
273 #endif
274
275 int close(int fd);
276 #endif //HAVE_MINGW
277
278
279 #define WNOHANG 0
280 #define WIFEXITED(x) 0
281 #define WEXITSTATUS(x) x
282 #define WIFSIGNALED(x) 0
283 #define SIGKILL 9
284 #define SIGUSR2 9999
285
286 #define HAVE_OLD_SOCKOPT
287
288 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
289 int nanosleep(const struct timespec*, struct timespec *);
290 struct tm *localtime_r(const time_t *, struct tm *);
291 struct tm *gmtime_r(const time_t *, struct tm *);
292 long int random(void);
293 void srandom(unsigned int seed);
294 int lstat(const char *, struct stat *);
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
301
302 int geteuid();
303
304 DIR *opendir(const char *name);
305 int closedir(DIR *dir);
306
307 struct passwd {
308     char *foo;
309 };
310
311 struct group {
312     char *foo;
313 };
314
315 struct passwd *getpwuid(uid_t);
316 struct group *getgrgid(uid_t);
317
318 #ifndef HAVE_MINGW
319 #define R_OK 04
320 #define W_OK 02
321 #endif //HAVE_MINGW
322
323 struct sigaction {
324     int sa_flags;
325     void (*sa_handler)(int);
326 };
327 #define sigfillset(x)
328 #define sigaction(a, b, c)
329
330 #define mkdir(p, m) win32_mkdir(p)
331 #define unlink win32_unlink
332 #define chdir win32_chdir
333 int syslog(int, const char *, const char *);
334 #define LOG_DAEMON 0
335 #define LOG_ERR 0
336
337 #ifndef HAVE_MINGW
338 int stat(const char *, struct stat *);
339 #ifdef __cplusplus
340 #define access _access
341 extern "C" _CRTIMP int __cdecl _access(const char *, int);
342 int execvp(const char *, char *[]);
343 extern "C" void *  __cdecl _alloca(size_t);
344 #endif
345 #endif //HAVE_MINGW
346
347 #define getpid _getpid
348
349 #define getppid() 0
350 #define gethostid() 0
351 #define getuid() 0
352 #define getgid() 0
353
354 #define getcwd win32_getcwd
355 #define chdir win32_chdir
356 #define fputs win32_fputs
357 char *win32_getcwd(char *buf, int maxlen);
358 int win32_chdir(const char *buf);
359 int win32_mkdir(const char *buf);
360 int win32_fputs(const char *string, FILE *stream);
361 int win32_unlink(const char *filename);
362
363 char* win32_cgets (char* buffer, int len);
364
365
366 int WSA_Init(void);
367
368 #ifdef HAVE_MINGW
369 void closelog();
370 #endif //HAVE_MINGW
371
372 #endif /* __COMPAT_H_ */