this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: use ICU for string conversions instead of iconv

+7 -58
+1
src/CoreServices/MacErrors.h
··· 8 8 #define unimpErr -4 9 9 #define fnfErr -43 // file not found 10 10 #define paramErr -50 11 + #define kLocalesBufferTooSmallErr -30001 11 12 #define kUCOutputBufferTooSmall -25340 12 13 13 14 #endif
+6 -58
src/CoreServices/MacLocales.cpp
··· 25 25 #include <unicode/coll.h> 26 26 #include <cstring> 27 27 #include <algorithm> 28 - #include <iconv.h> 29 28 #include <errno.h> 30 29 #include <cassert> 31 30 #include <string> 32 31 #include <map> 33 32 #include "../util/mutex.h" 34 33 35 - static iconv_t g_icUtf32ToUtf16 = nullptr; 36 - 37 34 static std::map<std::string,int> g_mapLocaleString; 38 35 static std::map<int,std::string> g_mapLocaleStringRev; 39 36 static Darling::Mutex g_mapLocaleStringMutex; 40 - 41 - __attribute__((constructor)) void initConversions() 42 - { 43 - g_icUtf32ToUtf16 = iconv_open("UTF-16", "UTF-32"); 44 - assert(g_icUtf32ToUtf16 != iconv_t(-1)); 45 - } 46 - 47 - __attribute__((destructor)) void exitConversions() 48 - { 49 - iconv_close(g_icUtf32ToUtf16); 50 - } 51 37 52 38 namespace Darling 53 39 { ··· 223 209 str += str2; 224 210 str += ")"; 225 211 226 - static_assert(sizeof(UChar) == 4 || sizeof(UChar) == 2, "Unsupported UChar size"); 227 - 228 - if (sizeof(UChar) == 4) 229 - { 230 - const UChar* buf = str.getTerminatedBuffer(); 231 - size_t inLen = (str.length()+1) * sizeof(UChar); 232 - size_t outLen = maxLen * sizeof(Utf16Char); 233 - const char* inbuf = reinterpret_cast<const char*>(buf); 234 - char* outbuf = reinterpret_cast<char*>(displayName); 235 - 236 - r = iconv(g_icUtf32ToUtf16, const_cast<char**>(&inbuf), &inLen, &outbuf, &outLen); 237 - 238 - if (r == size_t(-1)) 239 - { 240 - if (errno == E2BIG) 241 - { 242 - displayName[maxLen-1] = 0; 243 - r = maxLen; 244 - return -30001; 245 - } 246 - else 247 - { 248 - r = 0; 249 - *displayName = 0; 250 - return makeOSStatus(errnoLinuxToDarwin(errno)); 251 - } 252 - } 253 - } 254 - else if (sizeof(UChar) == sizeof(Utf16Char)) 255 - { 256 - if (str.length()+1 > maxLen) 257 - { 258 - *lenOut = str.length()+1; 259 - *displayName = 0; 260 - return -30001; 261 - } 262 - else 263 - { 264 - memcpy(displayName, str.getTerminatedBuffer(), (str.length()+1) * sizeof(UChar)); 265 - r = str.length()+1; 266 - } 267 - } 212 + int32_t req = str.extract(0, str.length(), (char*) displayName, maxLen * sizeof(Utf16Char), "UTF-16"); 213 + *lenOut = req / sizeof(Utf16Char); 268 214 269 - *lenOut = r; 270 - return 0; 215 + if (req > maxLen * sizeof(Utf16Char)) 216 + return kLocalesBufferTooSmallErr; 217 + else 218 + return noErr; 271 219 } 272 220 273 221 OSStatus LocaleCountNames(LocaleRef ref, LocaleOperationVariant variant, uint32_t nameMask, unsigned long* countOut)