-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompat.hpp
More file actions
124 lines (104 loc) · 2.71 KB
/
Copy pathcompat.hpp
File metadata and controls
124 lines (104 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* compat.hpp
*
* Created on: 15 de set de 2016
* Author: carlosfelipe.faruolo
*/
/// This header provides alternative implementations of POSIX-defined functions, for compatibilty purposes
#include <cstdlib>
#include <cstring>
#include <cctype>
// Dealing with specific compilers
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define FORCE_CUSTOM_LRINT_ENABLED
#define CUSTOM_STRCASECMP_DISABLED
#define CUSTOM_STRDUP_DISABLED
#define CUSTOM_SNPRINTF_ENABLED
#define strcasecmp _stricmp
#endif
#elif (defined(__GNUG__) || defined(__GNUC__))
#define CUSTOM_LRINT_DISABLED
#ifndef __STRICT_ANSI__
#define CUSTOM_STRCASECMP_DISABLED
#define CUSTOM_STRDUP_DISABLED
#endif
#endif
// If C++11 or C99, these POSIX functions are available
#if __cplusplus >= 201103L
#ifndef CUSTOM_LRINT_DISABLED
#define CUSTOM_LRINT_DISABLED
#endif
#endif
#if !defined(CUSTOM_LRINT_DISABLED) || defined(FORCE_CUSTOM_LRINT_ENABLED)
#ifdef __cplusplus
#include <cmath>
#else
#include <math.h>
#endif
long int lrint(double x)
{
//middle value point test
if(ceil(x+0.5) == floor(x+0.5))
{
int a = (int) ceil(x+0.5);
if(a%2 == 0)
return ceil(x);
else
return floor(x);
}
else return floor(x+0.5);
}
#endif
#ifndef CUSTOM_STRCASECMP_DISABLED
#include <cstring>
int strcasecmp( const char * str1, const char * str2)
{
unsigned int str1len = strlen(str1);
unsigned int str2len = strlen(str2);
if(str1len < str2len) return -str2[str1len];
if(str1len > str2len) return str1[str2len];
unsigned int i;
for(i = 0; i < str1len; i++)
if (tolower(str1[i]) != tolower(str2[i]))
return tolower(str1[i]) - tolower(str2[i]);
return 0;
}
#endif
#ifndef CUSTOM_STRDUP_DISABLED
char* strdup (const char *s)
{
char *d = (char*) malloc (strlen (s) + 1); // Allocate memory (Space for length plus nul)
if (d != NULL) strcpy (d,s); // Copy string if okay
return d; // Return the new string
}
#endif
#ifdef FORCE_CUSTOM_SNPRINTF_DISABLED
#undef CUSTOM_SNPRINTF_ENABLED
#endif
#ifdef CUSTOM_SNPRINTF_ENABLED
#include <cstdarg>
#include <cstdio>
#define vsnprintf c99_vsnprintf
#define snprintf c99_snprintf
static int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
static int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
}
#endif
// Include directly because old SDL versions don't.
#include <SDL/SDL_thread.h>