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