|
6 | 6 | XRCORE_API CInifile const* pSettings = nullptr; |
7 | 7 | XRCORE_API CInifile const* pSettingsAuth = nullptr; |
8 | 8 |
|
| 9 | +#if defined(LINUX) |
| 10 | +#include <stdint.h> |
| 11 | +#define MSVCRT_EINVAL 22 |
| 12 | +#define MSVCRT_ERANGE 34 |
| 13 | + |
| 14 | +#define MSVCRT_UI64_MAX (((uint64_t)0xffffffff << 32) | 0xffffffff) |
| 15 | + |
| 16 | +/** |
| 17 | + * from wine@dlls/msvcrt/string.c |
| 18 | + * |
| 19 | + * @param fileName |
| 20 | + * @param readOnly |
| 21 | + * @return |
| 22 | + */ |
| 23 | +int _cdecl _i64toa_s(int64_t value, char *str, size_t size, int radix){ |
| 24 | + uint64_t val; |
| 25 | + unsigned int digit; |
| 26 | + int is_negative; |
| 27 | + char buffer[65], *pos; |
| 28 | + size_t len; |
| 29 | + |
| 30 | + if (!(str != NULL)) |
| 31 | + return MSVCRT_EINVAL; |
| 32 | + if (!(size > 0)) |
| 33 | + return MSVCRT_EINVAL; |
| 34 | + if (!(radix >= 2 && radix <= 36)) { |
| 35 | + str[0] = '\0'; |
| 36 | + return MSVCRT_EINVAL; |
| 37 | + } |
| 38 | + |
| 39 | + if (value < 0 && radix == 10) { |
| 40 | + is_negative = 1; |
| 41 | + val = -value; |
| 42 | + } else { |
| 43 | + is_negative = 0; |
| 44 | + val = value; |
| 45 | + } |
| 46 | + |
| 47 | + pos = buffer + 64; |
| 48 | + *pos = '\0'; |
| 49 | + |
| 50 | + do { |
| 51 | + digit = val % radix; |
| 52 | + val /= radix; |
| 53 | + |
| 54 | + if (digit < 10) |
| 55 | + *--pos = '0' + digit; |
| 56 | + else |
| 57 | + *--pos = 'a' + digit - 10; |
| 58 | + } while (val != 0); |
| 59 | + |
| 60 | + if (is_negative) |
| 61 | + *--pos = '-'; |
| 62 | + |
| 63 | + len = buffer + 65 - pos; |
| 64 | + if (len > size) { |
| 65 | + size_t i; |
| 66 | + char *p = str; |
| 67 | + |
| 68 | + /* Copy the temporary buffer backwards up to the available number of |
| 69 | + * characters. Don't copy the negative sign if present. */ |
| 70 | + |
| 71 | + if (is_negative) { |
| 72 | + p++; |
| 73 | + size--; |
| 74 | + } |
| 75 | + |
| 76 | + for (pos = buffer + 63, i = 0; i < size; i++) |
| 77 | + *p++ = *pos--; |
| 78 | + |
| 79 | + str[0] = '\0'; |
| 80 | + return MSVCRT_ERANGE; |
| 81 | + } |
| 82 | + |
| 83 | + memcpy(str, pos, len); |
| 84 | + return 0; |
| 85 | +} |
| 86 | + |
| 87 | +int _cdecl _ui64toa_s(uint64_t value, char *str, size_t size, int radix) { |
| 88 | + char buffer[65], *pos; |
| 89 | + int digit; |
| 90 | + |
| 91 | + if (!(str != NULL)) |
| 92 | + return MSVCRT_EINVAL; |
| 93 | + if (!(size > 0)) |
| 94 | + return MSVCRT_EINVAL; |
| 95 | + if (!(radix >= 2 && radix <= 36)) { |
| 96 | + str[0] = '\0'; |
| 97 | + return MSVCRT_EINVAL; |
| 98 | + } |
| 99 | + |
| 100 | + pos = buffer + 64; |
| 101 | + *pos = '\0'; |
| 102 | + |
| 103 | + do { |
| 104 | + digit = value % radix; |
| 105 | + value /= radix; |
| 106 | + |
| 107 | + if (digit < 10) |
| 108 | + *--pos = '0' + digit; |
| 109 | + else |
| 110 | + *--pos = 'a' + digit - 10; |
| 111 | + } while (value != 0); |
| 112 | + |
| 113 | + if (buffer - pos + 65 > size) { |
| 114 | + return MSVCRT_EINVAL; |
| 115 | + } |
| 116 | + |
| 117 | + memcpy(str, pos, buffer - pos + 65); |
| 118 | + return 0; |
| 119 | +} |
| 120 | + |
| 121 | +LARGE_INTEGER _cdecl _atoi64( const char *str ) |
| 122 | +{ |
| 123 | + ULARGE_INTEGER RunningTotal = 0; |
| 124 | + char bMinus = 0; |
| 125 | + |
| 126 | + while (*str == ' ' || (*str >= '\011' && *str <= '\015')) { |
| 127 | + str++; |
| 128 | + } /* while */ |
| 129 | + |
| 130 | + if (*str == '+') { |
| 131 | + str++; |
| 132 | + } else if (*str == '-') { |
| 133 | + bMinus = 1; |
| 134 | + str++; |
| 135 | + } /* if */ |
| 136 | + |
| 137 | + while (*str >= '0' && *str <= '9') { |
| 138 | + RunningTotal = RunningTotal * 10 + *str - '0'; |
| 139 | + str++; |
| 140 | + } /* while */ |
| 141 | + |
| 142 | + return bMinus ? -RunningTotal : RunningTotal; |
| 143 | +} |
| 144 | + |
| 145 | +uint64_t _cdecl _strtoui64_l(const char *nptr, char **endptr, int base, locale_t locale) |
| 146 | +{ |
| 147 | + BOOL negative = FALSE; |
| 148 | + uint64_t ret = 0; |
| 149 | + |
| 150 | + |
| 151 | + if (!(nptr != NULL)) return 0; |
| 152 | + if (!(base == 0 || base >= 2)) return 0; |
| 153 | + if (!(base <= 36)) return 0; |
| 154 | + |
| 155 | + while(isspace(*nptr)) nptr++; |
| 156 | + |
| 157 | + if(*nptr == '-') { |
| 158 | + negative = TRUE; |
| 159 | + nptr++; |
| 160 | + } else if(*nptr == '+') |
| 161 | + nptr++; |
| 162 | + |
| 163 | + if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') { |
| 164 | + base = 16; |
| 165 | + nptr += 2; |
| 166 | + } |
| 167 | + |
| 168 | + if(base == 0) { |
| 169 | + if(*nptr=='0') |
| 170 | + base = 8; |
| 171 | + else |
| 172 | + base = 10; |
| 173 | + } |
| 174 | + |
| 175 | + while(*nptr) { |
| 176 | + char cur = tolower(*nptr); |
| 177 | + int v; |
| 178 | + |
| 179 | + if(isdigit(cur)) { |
| 180 | + if(cur >= '0'+base) |
| 181 | + break; |
| 182 | + v = *nptr-'0'; |
| 183 | + } else { |
| 184 | + if(cur<'a' || cur>='a'+base-10) |
| 185 | + break; |
| 186 | + v = cur-'a'+10; |
| 187 | + } |
| 188 | + |
| 189 | + nptr++; |
| 190 | + |
| 191 | + if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) { |
| 192 | + ret = MSVCRT_UI64_MAX; |
| 193 | + } else |
| 194 | + ret = ret*base + v; |
| 195 | + } |
| 196 | + |
| 197 | + if(endptr) |
| 198 | + *endptr = (char*)nptr; |
| 199 | + |
| 200 | + return negative ? -ret : ret; |
| 201 | +} |
| 202 | + |
| 203 | +uint64_t _cdecl _strtoui64(const char *nptr, char **endptr, int base) |
| 204 | +{ |
| 205 | + return _strtoui64_l(nptr, endptr, base, NULL); |
| 206 | +} |
| 207 | +#endif |
| 208 | + |
| 209 | + |
9 | 210 | CInifile* CInifile::Create(pcstr fileName, bool readOnly) |
10 | 211 | { |
11 | 212 | return new CInifile(fileName, readOnly); |
|
0 commit comments