• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // locale names
19 #ifdef _WIN32
20 // WARNING: Windows does not support UTF-8 codepages.
21 // Locales are "converted" using http://docs.moodle.org/dev/Table_of_locales
22 #define LOCALE_en_US_UTF_8     "English_United States.1252"
23 #define LOCALE_cs_CZ_ISO8859_2 "Czech_Czech Republic.1250"
24 #define LOCALE_fr_FR_UTF_8     "French_France.1252"
25 #define LOCALE_fr_CA_ISO8859_1 "French_Canada.1252"
26 #define LOCALE_ru_RU_UTF_8     "Russian_Russia.1251"
27 #define LOCALE_zh_CN_UTF_8     "Chinese_China.936"
28 #elif defined(__CloudABI__)
29 // Timezones are integrated into locales through LC_TIMEZONE_MASK on
30 // CloudABI. LC_ALL_MASK can only be used if a timezone has also been
31 // provided. UTC should be all right.
32 #define LOCALE_en_US_UTF_8     "en_US.UTF-8@UTC"
33 #define LOCALE_fr_FR_UTF_8     "fr_FR.UTF-8@UTC"
34 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1@UTC"
35 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2@UTC"
36 #define LOCALE_ru_RU_UTF_8     "ru_RU.UTF-8@UTC"
37 #define LOCALE_zh_CN_UTF_8     "zh_CN.UTF-8@UTC"
38 #else
39 #define LOCALE_en_US_UTF_8     "en_US.UTF-8"
40 #define LOCALE_fr_FR_UTF_8     "fr_FR.UTF-8"
41 #ifdef __linux__
42 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1"
43 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2"
44 #else
45 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1"
46 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2"
47 #endif
48 #define LOCALE_ru_RU_UTF_8     "ru_RU.UTF-8"
49 #define LOCALE_zh_CN_UTF_8     "zh_CN.UTF-8"
50 #endif
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string>
55 #if defined(_WIN32) || defined(__MINGW32__)
56 #include <io.h> // _mktemp_s
57 #else
58 #include <unistd.h> // close
59 #endif
60 
61 #if defined(_NEWLIB_VERSION) && defined(__STRICT_ANSI__)
62 // Newlib provides this, but in the header it's under __STRICT_ANSI__
63 extern "C" {
64   int mkstemp(char*);
65 }
66 #endif
67 
68 #ifndef __CloudABI__
69 inline
get_temp_file_name()70 std::string get_temp_file_name()
71 {
72 #if defined(__MINGW32__)
73     char Path[MAX_PATH + 1];
74     char FN[MAX_PATH + 1];
75     do { } while (0 == GetTempPath(MAX_PATH+1, Path));
76     do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN));
77     return FN;
78 #elif defined(_WIN32)
79     char Name[] = "libcxx.XXXXXX";
80     if (_mktemp_s(Name, sizeof(Name)) != 0) abort();
81     return Name;
82 #else
83     std::string Name;
84     int FD = -1;
85     do {
86         Name = "libcxx.XXXXXX";
87         FD = mkstemp(&Name[0]);
88         if (FD == -1 && errno == EINVAL) {
89             perror("mkstemp");
90             abort();
91         }
92     } while (FD == -1);
93     close(FD);
94     return Name;
95 #endif
96 }
97 #endif // __CloudABI__
98 
99 #endif // PLATFORM_SUPPORT_H
100