1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // Define a bunch of macros that can be used in the tests instead of 11 // implementation defined assumptions: 12 // - locale names 13 // - floating point number string output 14 15 #ifndef PLATFORM_SUPPORT_H 16 #define PLATFORM_SUPPORT_H 17 18 #include <__config> 19 20 // locale names 21 #ifdef _WIN32 22 // WARNING: Windows does not support UTF-8 codepages. 23 // Locales are "converted" using http://docs.moodle.org/dev/Table_of_locales 24 #define LOCALE_en_US_UTF_8 "English_United States.1252" 25 #define LOCALE_cs_CZ_ISO8859_2 "Czech_Czech Republic.1250" 26 #define LOCALE_fr_FR_UTF_8 "French_France.1252" 27 #define LOCALE_fr_CA_ISO8859_1 "French_Canada.1252" 28 #define LOCALE_ru_RU_UTF_8 "Russian_Russia.1251" 29 #define LOCALE_zh_CN_UTF_8 "Chinese_China.936" 30 #elif defined(__CloudABI__) 31 // Timezones are integrated into locales through LC_TIMEZONE_MASK on 32 // CloudABI. LC_ALL_MASK can only be used if a timezone has also been 33 // provided. UTC should be all right. 34 #define LOCALE_en_US_UTF_8 "en_US.UTF-8@UTC" 35 #define LOCALE_fr_FR_UTF_8 "fr_FR.UTF-8@UTC" 36 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1@UTC" 37 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2@UTC" 38 #define LOCALE_ru_RU_UTF_8 "ru_RU.UTF-8@UTC" 39 #define LOCALE_zh_CN_UTF_8 "zh_CN.UTF-8@UTC" 40 #else 41 #define LOCALE_en_US_UTF_8 "en_US.UTF-8" 42 #define LOCALE_fr_FR_UTF_8 "fr_FR.UTF-8" 43 #ifdef __linux__ 44 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1" 45 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2" 46 #else 47 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1" 48 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2" 49 #endif 50 #define LOCALE_ru_RU_UTF_8 "ru_RU.UTF-8" 51 #define LOCALE_zh_CN_UTF_8 "zh_CN.UTF-8" 52 #endif 53 54 #include <stdio.h> 55 #include <stdlib.h> 56 #include <string> 57 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) 58 #include <io.h> // _mktemp 59 #else 60 #include <unistd.h> // close 61 #endif 62 63 #if defined(_NEWLIB_VERSION) && defined(__STRICT_ANSI__) 64 // Newlib provies this, but in the header it's under __STRICT_ANSI__ 65 extern "C" { 66 int mkstemp(char*); 67 } 68 #endif 69 70 #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 71 inline 72 std::string get_temp_file_name()73get_temp_file_name() 74 { 75 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) 76 char Path[MAX_PATH+1]; 77 char FN[MAX_PATH+1]; 78 do { } while (0 == GetTempPath(MAX_PATH+1, Path)); 79 do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN)); 80 return FN; 81 #else 82 std::string Name; 83 int FD = -1; 84 do { 85 Name = "libcxx.XXXXXX"; 86 FD = mkstemp(&Name[0]); 87 if (FD == -1 && errno == EINVAL) { 88 perror("mkstemp"); 89 abort(); 90 } 91 } while (FD == -1); 92 close(FD); 93 return Name; 94 #endif 95 } 96 #endif // _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 97 98 #endif // PLATFORM_SUPPORT_H 99