2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
22 // Copyright transferred from Raider Solutions, Inc to
23 // Kern Sibbald and John Walker by express permission.
26 * Author : Christopher S. Hull
27 * Created On : Fri Jan 30 13:00:51 2004
33 #if !defined(__COMPAT_H_)
36 #define _STAT_H /* don't pull in MinGW stat.h */
40 #define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
43 #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC8+
44 #pragma warning(disable : 4996) // Either disable all deprecation warnings,
45 // #define _CRT_SECURE_NO_DEPRECATE // Or just turn off warnings about the newly deprecated CRT functions.
46 #elif !defined(HAVE_MINGW) && !defined(HAVE_WXCONSOLE)
53 /* Was defined in pthread.h before */
54 # define localtime_r( _clock, _result ) \
55 ( *(_result) = *localtime( (_clock) ), \
58 # define strtok_r( _s, _sep, _lasts ) \
59 ( *(_lasts) = strtok( (_s), (_sep) ) )
61 # define asctime_r( _tm, _buf ) \
62 ( strcpy( (_buf), asctime( (_tm) ) ), \
65 # define ctime_r( _clock, _buf ) \
66 ( strcpy( (_buf), ctime( (_clock) ) ), \
69 # define gmtime_r( _clock, _result ) \
70 ( *(_result) = *gmtime( (_clock) ), \
73 #define rand_r( _seed ) \
74 ( _seed == _seed? rand() : rand() )
80 #define _declspec __declspec
86 # define GWL_USERDATA GWLP_USERDATA
90 #define INT64 long long int
93 typedef UINT64 u_int64_t;
94 typedef UINT64 uint64_t;
95 typedef INT64 int64_t;
96 typedef UINT32 uint32_t;
97 typedef INT64 intmax_t;
98 typedef unsigned char uint8_t;
99 typedef unsigned short uint16_t;
100 typedef signed short int16_t;
101 typedef signed char int8_t;
102 typedef int __daddr_t;
104 #if !defined(HAVE_MINGW)
105 typedef long int32_t;
106 typedef float float32_t;
107 typedef double float64_t;
110 #if !defined(_MSC_VER) || (_MSC_VER < 1400) // VC8+
111 #ifndef _TIME_T_DEFINED
112 #define _TIME_T_DEFINED
117 #if __STDC__ && !defined(HAVE_MINGW)
118 typedef _dev_t dev_t;
119 #if !defined(HAVE_WXCONSOLE)
120 typedef __int64 ino_t;
124 typedef UINT32 u_int32_t;
125 typedef unsigned char u_int8_t;
126 typedef unsigned short u_int16_t;
128 #if !defined(HAVE_MINGW)
134 typedef UINT32 key_t;
136 #if defined(HAVE_MINGW)
138 typedef UINT32 uid_t;
139 typedef UINT32 gid_t;
142 typedef UINT32 uid_t;
143 typedef UINT32 gid_t;
144 typedef UINT32 mode_t;
145 typedef INT32 ssize_t;
146 typedef UINT32 size_t;
147 #define HAVE_SSIZE_T 1
149 #endif /* HAVE_MINGW */
160 #if !defined(__cplusplus)
169 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
170 #define _TIMEZONE_DEFINED
176 int strcasecmp(const char*, const char *);
177 int gettimeofday(struct timeval *, struct timezone *);
179 #if !defined(EETXTBUSY)
183 #if !defined(ETIMEDOUT)
187 #if !defined(ENOMEDIUM)
188 #define ENOMEDIUM 123
191 #if !defined(ENODATA)
196 * Stat packet that we use for Windows
213 uint32_t st_fattrs; /* Windows file attributes */
217 #define SOCK_CLOEXEC 0x00000000
221 #define S_IFMT 0170000 /* file type mask */
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 */
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 */
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)
239 #define S_ISBLK(x) (((x) & S_IFMT) == S_IFBLK)
240 #define S_ISFIFO(x) 0
242 #define S_IRGRP 000040
243 #define S_IWGRP 000020
244 #define S_IXGRP 000010
246 #define S_IROTH 00004
247 #define S_IWOTH 00002
248 #define S_IXOTH 00001
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
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
265 #define isascii __isascii
266 #define toascii __toascii
267 #define iscsymf __iscsymf
268 #define iscsym __iscsym
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 /* To know if we can use the VSSPathConvert function */
274 typedef BOOL (*t_pVSSPathConverter)();
276 void SetVSSPathConvert(t_pVSSPathConverter pPathConverter, t_pVSSPathConvert pPathConvert, t_pVSSPathConvertW pPathConvertW);
278 int lchown(const char *, uid_t uid, gid_t gid);
279 int chown(const char *, uid_t uid, gid_t gid);
280 #if !defined(HAVE_MINGW)
281 int chmod(const char *, mode_t mode);
283 #define O_NONBLOCK 04000
291 int fcntl(int fd, int cmd, long arg);
292 int fstat(intptr_t fd, struct stat *sb);
294 int inet_aton(const char *cp, struct in_addr *inp);
295 int binet_pton(int af, const char *src, void *dst);
296 int kill(pid_t pid, int signo);
299 int waitpid(int, int *, int);
301 #if !defined(HAVE_MINGW)
302 #define strncasecmp strnicmp
303 //int strncasecmp(const char*, const char *, int);
304 int utime(const char *filename, struct utimbuf *buf);
305 #define vsnprintf _vsnprintf
306 #define snprintf _snprintf
311 #define WIFEXITED(x) 0
312 #define WEXITSTATUS(x) x
313 #define WIFSIGNALED(x) 0
314 #define WTERMSIG(x) x
318 #define HAVE_OLD_SOCKOPT
321 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
322 int nanosleep(const struct timespec*, struct timespec *);
323 long int random(void);
324 void srandom(unsigned int seed);
325 int lstat(const char *, struct stat *);
326 int stat(const char *file, struct stat *sb);
327 long pathconf(const char *, int);
328 int readlink(const char *, char *, int);
329 int symlink(const char *path1, const char *path2);
330 #define _PC_PATH_MAX 1
331 #define _PC_NAME_MAX 2
335 DIR *opendir(const char *name);
336 int closedir(DIR *dir);
346 struct passwd *getpwuid(uid_t);
347 struct group *getgrgid(uid_t);
352 void (*sa_handler)(int);
354 #define sigfillset(x)
355 #define sigaction(a, b, c)
358 #define mkdir(p, m) win32_mkdir(p)
359 #define unlink win32_unlink
360 #define chdir win32_chdir
361 #define chmod win32_chmod
362 extern void syslog(int type, const char *fmt, ...);
363 #if !defined(LOG_DAEMON)
367 #if !defined(HAVE_MINGW)
370 int stat(const char *, struct stat *);
371 #if defined(__cplusplus)
372 #define access _access
373 extern "C" _CRTIMP int __cdecl _access(const char *, int);
374 int execvp(const char *, char *[]);
375 extern "C" void * __cdecl _alloca(size_t);
379 #define getpid _getpid
382 #define gethostid() 0
386 #define getcwd win32_getcwd
387 #define chdir win32_chdir
388 #define chmod win32_chmod
389 #define fputs win32_fputs
390 char *win32_getcwd(char *buf, int maxlen);
391 int win32_chdir(const char *buf);
392 int win32_mkdir(const char *buf);
393 int win32_fputs(const char *string, FILE *stream);
394 int win32_unlink(const char *filename);
395 int win32_chmod(const char *, mode_t);
398 char* win32_cgets (char* buffer, int len);
401 void Win32ConvCleanupCache();
403 #if defined(HAVE_MINGW)
405 void openlog(const char *ident, int option, int facility);
408 typedef DWORD EXECUTION_STATE;
409 #ifndef ES_CONTINUOUS
410 #define ES_CONTINUOUS 0x80000000
412 #ifndef ES_SYSTEM_REQUIRED
413 #define ES_SYSTEM_REQUIRED 0x00000001
415 #ifndef ES_DISPLAY_REQUIRED
416 #define ES_DISPLAY_REQUIRED 0x00000002
418 #ifndef ES_USER_PRESENT
419 # define ES_USER_PRESENT 0x00000004
422 WINBASEAPI EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE esFlags);
425 extern void LogErrorMsg(const char *message);
427 #if !defined(INVALID_FILE_ATTRIBUTES)
428 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
432 * Since the FileAttributes flag in Windows does not hold the
433 * dedup bit, we simplify the code by defining our own
436 #define FILE_ATTRIBUTE_DEDUP 0x80000000
437 #define CREATE_FOR_EXPORT 0 /* default in OpenEncryptedFileRaw */
439 #if defined(_MSC_VER)
440 inline unsigned long ffs(unsigned long word)
444 if (_BitScanForward(&index, word) != 0)
451 #define ffs __builtin_ffs
455 int win32_ftruncate(int fd, int64_t length);
456 int mkstemp(char *t);
458 void malloc_trim(int);
459 uint64_t get_memory_info(char *buf, int buflen);
462 #define ftruncate win32_ftruncate
465 #define O_DIRECTORY 0100000000
467 #define O_ENCRYPTED 0200000000
469 #endif /* __COMPAT_H_ */