]> Git Repo - cpuminer-multi.git/blame - compat.h
fix a few vstudio warnings
[cpuminer-multi.git] / compat.h
CommitLineData
b089cc9f
LJ
1#ifndef __COMPAT_H__
2#define __COMPAT_H__
3
4#ifdef WIN32
5
6#include <windows.h>
88d567d5
TP
7#include <time.h>
8
2a5ea599 9#ifndef localtime_r
88d567d5 10#define localtime_r(src, dst) localtime_s(dst, src)
2a5ea599 11#endif
b089cc9f
LJ
12
13#define sleep(secs) Sleep((secs) * 1000)
14
15enum {
16 PRIO_PROCESS = 0,
17};
18
6e51671e 19extern int opt_priority;
1720eb84 20static __inline int setpriority(int which, int who, int prio)
b089cc9f 21{
6e51671e
TP
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);
b089cc9f
LJ
43}
44
233126d3
TP
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__
13529dde 51#define __thread __declspec(thread)
233126d3
TP
52#define _ALIGN(x) __declspec(align(x))
53typedef int ssize_t;
26192b50
TP
54
55#include <stdlib.h>
99d6dfb0
TP
56// This static var is made to be compatible with linux/mingw (no free on string result)
57// This is not thread safe but we only use that once on process start
58static char dirname_buffer[_MAX_PATH] = { 0 };
26192b50 59static __inline char * dirname(char *file) {
99d6dfb0
TP
60 char drive[_MAX_DRIVE] = { 0 };
61 char dir[_MAX_DIR] = { 0 };
62 char fname[_MAX_FNAME], ext[_MAX_EXT];
26192b50 63 _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
99d6dfb0
TP
64 if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') {
65 dir[strlen(dir) - 1] = '\0';
66 }
67 sprintf(dirname_buffer, "%s%s", drive, dir);
68 return &dirname_buffer[0];
26192b50 69}
233126d3
TP
70#endif
71
b089cc9f
LJ
72#endif /* WIN32 */
73
233126d3
TP
74#ifndef _MSC_VER
75#define _ALIGN(x) __attribute__ ((aligned(x)))
76#endif
77
78#undef unlikely
79#undef likely
80#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
81#define unlikely(expr) (__builtin_expect(!!(expr), 0))
82#define likely(expr) (__builtin_expect(!!(expr), 1))
83#else
84#define unlikely(expr) (expr)
85#define likely(expr) (expr)
86#endif
87
8e1246b6
TP
88#ifndef WIN32
89#define MAX_PATH PATH_MAX
90#endif
91
b089cc9f 92#endif /* __COMPAT_H__ */
This page took 0.0419 seconds and 4 git commands to generate.