]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/compat/compat.h
Correct a minor build problem with wx-console.
[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 struct stat
172 {
173     _dev_t      st_dev;
174     uint64_t    st_ino;
175     uint16_t    st_mode;
176     int16_t     st_nlink;
177     uint32_t    st_uid;
178     uint32_t    st_gid;
179     _dev_t      st_rdev;
180     uint64_t    st_size;
181     time_t      st_atime;
182     time_t      st_mtime;
183     time_t      st_ctime;
184     uint32_t    st_blksize;
185     uint64_t    st_blocks;
186 };
187
188 #undef  S_IFMT
189 #define S_IFMT         0170000         /* file type mask */
190 #undef  S_IFDIR
191 #define S_IFDIR        0040000         /* directory */
192 #define S_IFCHR        0020000         /* character special */
193 #define S_IFIFO        0010000         /* pipe */
194 #undef  S_IFREG
195 #define S_IFREG        0100000         /* regular */
196 #define S_IREAD        0000400         /* read permission, owner */
197 #define S_IWRITE       0000200         /* write permission, owner */
198 #define S_IEXEC        0000100         /* execute/search permission, owner */
199
200 #define S_IRUSR         S_IREAD
201 #define S_IWUSR         S_IWRITE
202 #define S_IXUSR         S_IEXEC
203 #define S_ISREG(x)  (((x) & S_IFREG) == S_IFREG)
204 #define S_ISDIR(x)  (((x) & S_IFDIR) == S_IFDIR)
205 #define S_ISCHR(x) 0
206 #define S_ISBLK(x) 0
207 #define S_ISFIFO(x) 0
208 #endif //HAVE_MINGW
209
210 #define S_IRGRP         000040
211 #define S_IWGRP         000020
212 #define S_IXGRP         000010
213
214 #define S_IROTH         00004
215 #define S_IWOTH         00002
216 #define S_IXOTH         00001
217
218 #define S_IRWXO         000007
219 #define S_IRWXG         000070
220 #define S_ISUID         004000
221 #define S_ISGID         002000
222 #define S_ISVTX         001000
223 #define S_ISSOCK(x) 0
224 #define S_ISLNK(x)      0
225
226 #if __STDC__
227 #define O_RDONLY _O_RDONLY
228 #define O_WRONLY _O_WRONLY
229 #define O_RDWR   _O_RDWR
230 #define O_CREAT  _O_CREAT
231 #define O_TRUNC  _O_TRUNC
232
233 #define isascii __isascii
234 #define toascii __toascii
235 #define iscsymf __iscsymf
236 #define iscsym  __iscsym
237 #endif
238
239
240 int umask(int);
241 int lchown(const char *, uid_t uid, gid_t gid);
242 int chown(const char *, uid_t uid, gid_t gid);
243 int chmod(const char *, mode_t mode);
244 off_t lseek(int, off_t, int);
245 int inet_aton(const char *cp, struct in_addr *inp);
246 int kill(int pid, int signo);
247 int pipe(int []);
248 int fork();
249 int dup2(int, int);
250 int waitpid(int, int *, int);
251
252 #ifndef HAVE_MINGW
253 int utime(const char *filename, struct utimbuf *buf);
254 int open(const char *, int, int);
255 #define vsnprintf __vsnprintf
256 int __vsnprintf(char *s, size_t count, const char *format, va_list args);
257
258 #define vsprintf __vsprintf
259 int __vsprintf(char *s, const char *format, va_list args);
260
261 #define snprintf __snprintf
262 int __snprintf(char *str, size_t count, const char *fmt, ...);
263
264 #define sprintf __sprintf
265 int __sprintf(char *str, const char *fmt, ...);
266
267 #ifndef HAVE_WXCONSOLE
268 ssize_t read(int fd, void *, ssize_t nbytes);
269 ssize_t write(int fd, const void *, ssize_t nbytes);
270 #endif
271
272 int close(int fd);
273 #endif //HAVE_MINGW
274
275
276 #define WNOHANG 0
277 #define WIFEXITED(x) 0
278 #define WEXITSTATUS(x) x
279 #define WIFSIGNALED(x) 0
280 #define SIGKILL 9
281 #define SIGUSR2 9999
282
283 #define HAVE_OLD_SOCKOPT
284
285 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
286 int nanosleep(const struct timespec*, struct timespec *);
287 struct tm *localtime_r(const time_t *, struct tm *);
288 struct tm *gmtime_r(const time_t *, struct tm *);
289 long int random(void);
290 void srandom(unsigned int seed);
291 int lstat(const char *, struct stat *);
292 long pathconf(const char *, int);
293 int readlink(const char *, char *, int);
294 #define _PC_PATH_MAX 1
295 #define _PC_NAME_MAX 2
296
297
298
299 int geteuid();
300
301 DIR *opendir(const char *name);
302 int closedir(DIR *dir);
303
304 struct passwd {
305     char *foo;
306 };
307
308 struct group {
309     char *foo;
310 };
311
312 struct passwd *getpwuid(uid_t);
313 struct group *getgrgid(uid_t);
314
315 #ifndef HAVE_MINGW
316 #define R_OK 04
317 #define W_OK 02
318 #endif //HAVE_MINGW
319
320 struct sigaction {
321     int sa_flags;
322     void (*sa_handler)(int);
323 };
324 #define sigfillset(x)
325 #define sigaction(a, b, c)
326
327 #define mkdir(p, m) win32_mkdir(p)
328 #define unlink win32_unlink
329 #define chdir win32_chdir
330 int syslog(int, const char *, const char *);
331 #define LOG_DAEMON 0
332 #define LOG_ERR 0
333
334 #ifndef HAVE_MINGW
335 int stat(const char *, struct stat *);
336 #ifdef __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 fputs win32_fputs
354 char *win32_getcwd(char *buf, int maxlen);
355 int win32_chdir(const char *buf);
356 int win32_mkdir(const char *buf);
357 int win32_fputs(const char *string, FILE *stream);
358 int win32_unlink(const char *filename);
359
360 char* win32_cgets (char* buffer, int len);
361
362
363 int WSA_Init(void);
364
365 #ifdef HAVE_MINGW
366 void closelog();
367 #endif //HAVE_MINGW
368
369 #endif /* __COMPAT_H_ */