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 https://docs.moodle.org/dev/Table_of_locales 22#define LOCALE_en_US "en-US" 23#define LOCALE_en_US_UTF_8 "en-US" 24#define LOCALE_cs_CZ_ISO8859_2 "cs-CZ" 25#define LOCALE_fr_FR_UTF_8 "fr-FR" 26#define LOCALE_fr_CA_ISO8859_1 "fr-CA" 27#define LOCALE_ru_RU_UTF_8 "ru-RU" 28#define LOCALE_zh_CN_UTF_8 "zh-CN" 29#elif defined(__CloudABI__) 30// Timezones are integrated into locales through LC_TIMEZONE_MASK on 31// CloudABI. LC_ALL_MASK can only be used if a timezone has also been 32// provided. UTC should be all right. 33#define LOCALE_en_US "en_US" 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 "en_US" 42#define LOCALE_en_US_UTF_8 "en_US.UTF-8" 43#define LOCALE_fr_FR_UTF_8 "fr_FR.UTF-8" 44#ifdef __linux__ 45#define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1" 46#define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2" 47#else 48#define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1" 49#define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2" 50#endif 51#define LOCALE_ru_RU_UTF_8 "ru_RU.UTF-8" 52#define LOCALE_zh_CN_UTF_8 "zh_CN.UTF-8" 53#endif 54 55#include <stdio.h> 56#include <stdlib.h> 57#include <codecvt> 58#include <locale> 59#include <string> 60#if defined(_WIN32) || defined(__MINGW32__) 61#include <io.h> // _mktemp_s 62#else 63#include <unistd.h> // close 64#endif 65 66#if defined(_NEWLIB_VERSION) && defined(__STRICT_ANSI__) 67// Newlib provides this, but in the header it's under __STRICT_ANSI__ 68extern "C" { 69 int mkstemp(char*); 70} 71#endif 72 73#ifndef __CloudABI__ 74inline 75std::string get_temp_file_name() 76{ 77#if defined(__MINGW32__) 78 char Path[MAX_PATH + 1]; 79 char FN[MAX_PATH + 1]; 80 do { } while (0 == GetTempPath(MAX_PATH+1, Path)); 81 do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN)); 82 return FN; 83#elif defined(_WIN32) 84 char Name[] = "libcxx.XXXXXX"; 85 if (_mktemp_s(Name, sizeof(Name)) != 0) abort(); 86 return Name; 87#else 88 std::string Name; 89 int FD = -1; 90 do { 91 Name = "libcxx.XXXXXX"; 92 FD = mkstemp(&Name[0]); 93 if (FD == -1 && errno == EINVAL) { 94 perror("mkstemp"); 95 abort(); 96 } 97 } while (FD == -1); 98 close(FD); 99 return Name; 100#endif 101} 102 103#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 104inline 105std::wstring get_wide_temp_file_name() 106{ 107 return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> >().from_bytes( 108 get_temp_file_name()); 109} 110#endif // _LIBCPP_HAS_OPEN_WITH_WCHAR 111 112#endif // __CloudABI__ 113 114#endif // PLATFORM_SUPPORT_H 115