Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/src/rc_compat.h
4246 views
1
#ifndef RC_COMPAT_H
2
#define RC_COMPAT_H
3
4
#ifdef _WIN32
5
#ifndef WIN32_LEAN_AND_MEAN
6
#define WIN32_LEAN_AND_MEAN
7
#endif
8
#include <windows.h>
9
#endif
10
11
#include "rc_export.h"
12
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <string.h>
16
17
RC_BEGIN_C_DECLS
18
19
#if defined(MINGW) || defined(__MINGW32__) || defined(__MINGW64__)
20
21
/* MinGW redefinitions */
22
23
#define RC_NO_VARIADIC_MACROS 1
24
25
#elif defined(_MSC_VER)
26
27
/* Visual Studio redefinitions */
28
29
#ifndef strcasecmp
30
#define strcasecmp _stricmp
31
#endif
32
#ifndef strncasecmp
33
#define strncasecmp _strnicmp
34
#endif
35
#ifndef strdup
36
#define strdup _strdup
37
#endif
38
39
#elif __STDC_VERSION__ < 199901L
40
41
/* C89 redefinitions */
42
#define RC_C89_HELPERS 1
43
44
#define RC_NO_VARIADIC_MACROS 1
45
46
#ifndef snprintf
47
extern int rc_snprintf(char* buffer, size_t size, const char* format, ...);
48
#define snprintf rc_snprintf
49
#endif
50
51
#ifndef strncasecmp
52
extern int rc_strncasecmp(const char* left, const char* right, size_t length);
53
#define strncasecmp rc_strncasecmp
54
#endif
55
56
#ifndef strcasecmp
57
extern int rc_strcasecmp(const char* left, const char* right);
58
#define strcasecmp rc_strcasecmp
59
#endif
60
61
#ifndef strdup
62
extern char* rc_strdup(const char* str);
63
#define strdup rc_strdup
64
#endif
65
66
#endif /* __STDC_VERSION__ < 199901L */
67
68
#ifndef __STDC_SECURE_LIB__
69
/* _CRT_SECURE_NO_WARNINGS redefinitions */
70
#define strcpy_s(dest, sz, src) strcpy(dest, src)
71
#define sscanf_s sscanf
72
73
/* NOTE: Microsoft secure gmtime_s parameter order differs from C11 standard */
74
#include <time.h>
75
extern struct tm* rc_gmtime_s(struct tm* buf, const time_t* timer);
76
#define gmtime_s rc_gmtime_s
77
#endif
78
79
#ifdef RC_NO_THREADS
80
typedef int rc_mutex_t;
81
82
#define rc_mutex_init(mutex)
83
#define rc_mutex_destroy(mutex)
84
#define rc_mutex_lock(mutex)
85
#define rc_mutex_unlock(mutex)
86
#else
87
#if defined(_WIN32)
88
typedef struct rc_mutex_t {
89
#if defined(WINVER) && WINVER >= 0x0600
90
/* Windows Vista and later can use a slim reader/writer (SRW) lock */
91
SRWLOCK srw_lock;
92
/* Current thread owner needs to be tracked (for recursive mutex usage) */
93
DWORD owner;
94
DWORD count;
95
#else
96
/* Pre-Vista must use a critical section */
97
CRITICAL_SECTION critical_section;
98
#endif
99
} rc_mutex_t;
100
#elif defined(GEKKO)
101
#include <ogcsys.h>
102
typedef struct rc_mutex_t {
103
mutex_t handle;
104
} rc_mutex_t;
105
#elif defined(_3DS)
106
#include <3ds/synchronization.h>
107
typedef RecursiveLock rc_mutex_t;
108
#else
109
#include <pthread.h>
110
typedef pthread_mutex_t rc_mutex_t;
111
#endif
112
113
void rc_mutex_init(rc_mutex_t* mutex);
114
void rc_mutex_destroy(rc_mutex_t* mutex);
115
void rc_mutex_lock(rc_mutex_t* mutex);
116
void rc_mutex_unlock(rc_mutex_t* mutex);
117
#endif
118
119
RC_END_C_DECLS
120
121
#endif /* RC_COMPAT_H */
122
123