Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
litecoincash-project
GitHub Repository: litecoincash-project/cpuminer-multi
Path: blob/master/compat.h
548 views
1
#ifndef __COMPAT_H__
2
#define __COMPAT_H__
3
4
#ifdef WIN32
5
6
#include <windows.h>
7
#include <time.h>
8
9
#ifndef localtime_r
10
#define localtime_r(src, dst) localtime_s(dst, src)
11
#endif
12
13
#define sleep(secs) Sleep((secs) * 1000)
14
15
enum {
16
PRIO_PROCESS = 0,
17
};
18
19
extern int opt_priority;
20
static __inline int setpriority(int which, int who, int prio)
21
{
22
switch (opt_priority) {
23
case 5:
24
prio = THREAD_PRIORITY_TIME_CRITICAL;
25
break;
26
case 4:
27
prio = THREAD_PRIORITY_HIGHEST;
28
break;
29
case 3:
30
prio = THREAD_PRIORITY_ABOVE_NORMAL;
31
break;
32
case 2:
33
prio = THREAD_PRIORITY_NORMAL;
34
break;
35
case 1:
36
prio = THREAD_PRIORITY_BELOW_NORMAL;
37
break;
38
case 0:
39
default:
40
prio = THREAD_PRIORITY_IDLE;
41
}
42
return -!SetThreadPriority(GetCurrentThread(), prio);
43
}
44
45
#ifdef _MSC_VER
46
#define snprintf(...) _snprintf(__VA_ARGS__)
47
#define strdup(...) _strdup(__VA_ARGS__)
48
#define strncasecmp(x,y,z) _strnicmp(x,y,z)
49
#define strcasecmp(x,y) _stricmp(x,y)
50
#define __func__ __FUNCTION__
51
#define __thread __declspec(thread)
52
#define _ALIGN(x) __declspec(align(x))
53
typedef int ssize_t;
54
55
__inline int msver(void) {
56
switch (_MSC_VER) {
57
case 1500: return 2008;
58
case 1600: return 2010;
59
case 1700: return 2012;
60
case 1800: return 2013;
61
case 1900: return 2015;
62
default: return (_MSC_VER/100);
63
}
64
}
65
66
#include <stdlib.h>
67
// This static var is made to be compatible with linux/mingw (no free on string result)
68
// This is not thread safe but we only use that once on process start
69
static char dirname_buffer[_MAX_PATH] = { 0 };
70
static __inline char * dirname(char *file) {
71
char drive[_MAX_DRIVE] = { 0 };
72
char dir[_MAX_DIR] = { 0 };
73
char fname[_MAX_FNAME], ext[_MAX_EXT];
74
_splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
75
if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') {
76
dir[strlen(dir) - 1] = '\0';
77
}
78
sprintf(dirname_buffer, "%s%s", drive, dir);
79
return &dirname_buffer[0];
80
}
81
#endif
82
83
#endif /* WIN32 */
84
85
#ifndef _MSC_VER
86
#define _ALIGN(x) __attribute__ ((aligned(x)))
87
#endif
88
89
#undef unlikely
90
#undef likely
91
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
92
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
93
#define likely(expr) (__builtin_expect(!!(expr), 1))
94
#else
95
#define unlikely(expr) (expr)
96
#define likely(expr) (expr)
97
#endif
98
99
#ifndef WIN32
100
#define MAX_PATH PATH_MAX
101
#endif
102
103
#endif /* __COMPAT_H__ */
104
105