Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 18 | #include <__config> |
| 19 | |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 20 | // locale names |
Marshall Clow | a22d2ad | 2013-03-18 17:04:29 +0000 | [diff] [blame] | 21 | #ifdef _WIN32 |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 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" |
Ed Schouten | 2020d8a | 2015-03-09 12:04:16 +0000 | [diff] [blame] | 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" |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 40 | #else |
| 41 | #define LOCALE_en_US_UTF_8 "en_US.UTF-8" |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 42 | #define LOCALE_fr_FR_UTF_8 "fr_FR.UTF-8" |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 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 |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 47 | #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1" |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 48 | #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2" |
| 49 | #endif |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 54 | #include <stdio.h> |
| 55 | #include <stdlib.h> |
| 56 | #include <string> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 57 | #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) |
| 58 | #include <io.h> // _mktemp |
Eric Fiselier | 682132b | 2014-08-19 17:52:40 +0000 | [diff] [blame] | 59 | #else |
| 60 | #include <unistd.h> // close |
Howard Hinnant | ae2b90b | 2013-10-06 21:14:05 +0000 | [diff] [blame] | 61 | #endif |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 62 | |
Jonathan Roelofs | 2f2daa1 | 2014-12-11 20:56:40 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 70 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 71 | inline |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 72 | std::string |
| 73 | get_temp_file_name() |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 74 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 75 | #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) |
| 76 | char Path[MAX_PATH+1]; |
| 77 | char FN[MAX_PATH+1]; |
Eric Fiselier | 7aa3806 | 2016-04-29 01:22:16 +0000 | [diff] [blame] | 78 | do { } while (0 == GetTempPath(MAX_PATH+1, Path)); |
| 79 | do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN)); |
| 80 | return FN; |
Howard Hinnant | ae2b90b | 2013-10-06 21:14:05 +0000 | [diff] [blame] | 81 | #else |
Jonathan Roelofs | 6f10d47 | 2014-08-19 13:56:56 +0000 | [diff] [blame] | 82 | std::string Name; |
| 83 | int FD = -1; |
| 84 | do { |
Dan Albert | 1bd299a | 2015-02-13 03:02:28 +0000 | [diff] [blame] | 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); |
Jonathan Roelofs | 6f10d47 | 2014-08-19 13:56:56 +0000 | [diff] [blame] | 92 | close(FD); |
| 93 | return Name; |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 94 | #endif |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 95 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 96 | #endif // _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | 06d8bf6 | 2013-03-22 20:05:40 +0000 | [diff] [blame] | 97 | |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 98 | #endif // PLATFORM_SUPPORT_H |