]>
Commit | Line | Data |
---|---|---|
b089cc9f LJ |
1 | #ifndef __COMPAT_H__ |
2 | #define __COMPAT_H__ | |
3 | ||
4 | #ifdef WIN32 | |
5 | ||
6 | #include <windows.h> | |
7 | ||
8 | #define sleep(secs) Sleep((secs) * 1000) | |
9 | ||
10 | enum { | |
11 | PRIO_PROCESS = 0, | |
12 | }; | |
13 | ||
6e51671e | 14 | extern int opt_priority; |
1720eb84 | 15 | static __inline int setpriority(int which, int who, int prio) |
b089cc9f | 16 | { |
6e51671e TP |
17 | switch (opt_priority) { |
18 | case 5: | |
19 | prio = THREAD_PRIORITY_TIME_CRITICAL; | |
20 | break; | |
21 | case 4: | |
22 | prio = THREAD_PRIORITY_HIGHEST; | |
23 | break; | |
24 | case 3: | |
25 | prio = THREAD_PRIORITY_ABOVE_NORMAL; | |
26 | break; | |
27 | case 2: | |
28 | prio = THREAD_PRIORITY_NORMAL; | |
29 | break; | |
30 | case 1: | |
31 | prio = THREAD_PRIORITY_BELOW_NORMAL; | |
32 | break; | |
33 | case 0: | |
34 | default: | |
35 | prio = THREAD_PRIORITY_IDLE; | |
36 | } | |
37 | return -!SetThreadPriority(GetCurrentThread(), prio); | |
b089cc9f LJ |
38 | } |
39 | ||
233126d3 TP |
40 | #ifdef _MSC_VER |
41 | #define snprintf(...) _snprintf(__VA_ARGS__) | |
42 | #define strdup(...) _strdup(__VA_ARGS__) | |
43 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) | |
44 | #define strcasecmp(x,y) _stricmp(x,y) | |
45 | #define __func__ __FUNCTION__ | |
13529dde | 46 | #define __thread __declspec(thread) |
233126d3 TP |
47 | #define _ALIGN(x) __declspec(align(x)) |
48 | typedef int ssize_t; | |
26192b50 TP |
49 | |
50 | #include <stdlib.h> | |
99d6dfb0 TP |
51 | // This static var is made to be compatible with linux/mingw (no free on string result) |
52 | // This is not thread safe but we only use that once on process start | |
53 | static char dirname_buffer[_MAX_PATH] = { 0 }; | |
26192b50 | 54 | static __inline char * dirname(char *file) { |
99d6dfb0 TP |
55 | char drive[_MAX_DRIVE] = { 0 }; |
56 | char dir[_MAX_DIR] = { 0 }; | |
57 | char fname[_MAX_FNAME], ext[_MAX_EXT]; | |
26192b50 | 58 | _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); |
99d6dfb0 TP |
59 | if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') { |
60 | dir[strlen(dir) - 1] = '\0'; | |
61 | } | |
62 | sprintf(dirname_buffer, "%s%s", drive, dir); | |
63 | return &dirname_buffer[0]; | |
26192b50 | 64 | } |
233126d3 TP |
65 | #endif |
66 | ||
b089cc9f LJ |
67 | #endif /* WIN32 */ |
68 | ||
233126d3 TP |
69 | #ifndef _MSC_VER |
70 | #define _ALIGN(x) __attribute__ ((aligned(x))) | |
71 | #endif | |
72 | ||
73 | #undef unlikely | |
74 | #undef likely | |
75 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) | |
76 | #define unlikely(expr) (__builtin_expect(!!(expr), 0)) | |
77 | #define likely(expr) (__builtin_expect(!!(expr), 1)) | |
78 | #else | |
79 | #define unlikely(expr) (expr) | |
80 | #define likely(expr) (expr) | |
81 | #endif | |
82 | ||
8e1246b6 TP |
83 | #ifndef WIN32 |
84 | #define MAX_PATH PATH_MAX | |
85 | #endif | |
86 | ||
b089cc9f | 87 | #endif /* __COMPAT_H__ */ |