50 #ifndef COMMON_SYSTEM_H 51 #define COMMON_SYSTEM_H 53 #if defined(HAVE_CONFIG_H) 66 #define snprintf c99_snprintf 67 #define vsnprintf c99_vsnprintf 70 #define strtoll _strtoi64 71 #define HAVE_STRTOLL 1 75 #define strtoull _strtoui64 76 #define HAVE_STRTOULL 1 79 #if !defined(XOREOS_LITTLE_ENDIAN) && !defined(XOREOS_BIG_ENDIAN) 80 #define XOREOS_LITTLE_ENDIAN 1 83 #define FORCEINLINE __forceinline 84 #define PLUGIN_EXPORT __declspec(dllexport) 86 static FORCEINLINE int c99_vsnprintf(
char *str,
size_t size,
const char *format, va_list ap) {
90 count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
92 count = _vscprintf(format, ap);
97 static FORCEINLINE int c99_snprintf(
char *str,
size_t size,
const char *format, ...) {
101 va_start(ap, format);
102 count = c99_vsnprintf(str, size, format, ap);
112 #define IGNORE_UNUSED_VARIABLES __pragma(warning(disable : 4101)) 114 #elif defined(__MINGW32__) 116 #if !defined(XOREOS_LITTLE_ENDIAN) && !defined(XOREOS_BIG_ENDIAN) 117 #define XOREOS_LITTLE_ENDIAN 1 120 #define PLUGIN_EXPORT __declspec(dllexport) 128 #if !defined(XOREOS_LITTLE_ENDIAN) && !defined(XOREOS_BIG_ENDIAN) 129 #if defined(HAVE_CONFIG_H) 130 #if defined(WORDS_BIGENDIAN) 131 #define XOREOS_BIG_ENDIAN 1 133 #define XOREOS_LITTLE_ENDIAN 1 139 #error No system type defined 145 #if defined(__GNUC__) 146 #define PACKED_STRUCT __attribute__((__packed__)) 147 #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y))) 151 #define IGNORE_UNUSED_VARIABLES _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \ 152 _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") 155 #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 156 #define FORCEINLINE inline __attribute__((__always_inline__)) 160 #define PACKED_STRUCT 161 #define GCC_PRINTF(x,y) 164 #if defined(__cplusplus) 167 #if defined(__GNUC__) 168 #define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) 170 #define UNUSED(x) UNUSED_ ## x 174 #if defined(__clang__) 176 #undef IGNORE_UNUSED_VARIABLES 177 #define IGNORE_UNUSED_VARIABLES _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") 185 #define strtof c99_strtof 188 return (
float) strtod(nptr, endptr);
191 #define HAVE_STRTOF 1 195 #define strtoll c99_strtoll 202 #define LLONG_MAX 0x7FFFFFFFFFFFFFFFlL 206 #define LLONG_MIN (-0x7FFFFFFFFFFFFFFFLL-1) 217 static long long c99_strtoll(
const char *nptr,
char **endptr,
int base) {
219 long long acc, cutoff;
221 int neg, any, cutlim;
230 c = (
unsigned char) *s++;
231 }
while (isspace(c));
240 if ((base == 0 || base == 16) &&
241 c ==
'0' && (*s ==
'x' || *s ==
'X')) {
247 base = c ==
'0' ? 8 : 10;
268 cutlim = cutoff % base;
277 for (acc = 0, any = 0;; c = (
unsigned char) *s++) {
281 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
289 if (acc < cutoff || (acc == cutoff && c > cutlim)) {
299 if (acc > cutoff || (acc == cutoff && c > cutlim)) {
311 *endptr = any ?
const_cast<char *
>(s - 1) : const_cast<char *>(nptr);
315 #define HAVE_STRTOLL 1 318 #ifndef HAVE_STRTOULL 319 #define strtoull c99_strtoull 326 #define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL 337 static unsigned long long c99_strtoull(
const char *nptr,
char **endptr,
int base) {
339 unsigned long long acc, cutoff;
341 int neg, any, cutlim;
348 c = (
unsigned char) *s++;
349 }
while (isspace(c));
358 if ((base == 0 || base == 16) &&
359 c ==
'0' && (*s ==
'x' || *s ==
'X')) {
365 base = c ==
'0' ? 8 : 10;
367 cutoff =
ULLONG_MAX / (
unsigned long long)base;
368 cutlim =
ULLONG_MAX % (
unsigned long long)base;
369 for (acc = 0, any = 0;; c = (
unsigned char) *s++) {
373 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
380 if (acc > cutoff || (acc == cutoff && c > cutlim)) {
386 acc *=
static_cast<unsigned long long>(base);
393 *endptr = any ?
const_cast<char *
>(s - 1) : const_cast<char *>(nptr);
397 #define HAVE_STRTOULL 1 401 #if __cplusplus < 201103L 402 #define XOREOS_EXPLICIT_OPERATOR_CONV 404 #define XOREOS_EXPLICIT_OPERATOR_CONV explicit 411 #define FORCEINLINE inline 415 #define STRINGBUFLEN 1024 419 #define MAXPATHLEN 256 422 #ifndef IGNORE_UNUSED_VARIABLES 423 #define IGNORE_UNUSED_VARIABLES 426 #endif // COMMON_SYSTEM_H Compiler-specific defines to declare a function non-returning.
static FORCEINLINE float c99_strtof(const char *nptr, char **endptr)
static long long c99_strtoll(const char *nptr, char **endptr, int base)
Convert a string to a long long.
static unsigned long long c99_strtoull(const char *nptr, char **endptr, int base)
Convert a string to an unsigned long long.
Compiler-specific defines to mark an implicit switch-case fallthrough.