blob: 233e721ff515537c7519b8e4fd8640c34de3ca7e [file] [log] [blame]
Howard Hinnantc0d0cba2011-10-03 15:23:59 +00001//===----------------------------------------------------------------------===//
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 Albert1d4a1ed2016-05-25 22:36:09 -070018#include <__config>
19
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000020// locale names
Marshall Clowa22d2ad2013-03-18 17:04:29 +000021#ifdef _WIN32
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000022// 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 Schouten2020d8a2015-03-09 12:04:16 +000030#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 Hinnantc0d0cba2011-10-03 15:23:59 +000040#else
41#define LOCALE_en_US_UTF_8 "en_US.UTF-8"
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000042#define LOCALE_fr_FR_UTF_8 "fr_FR.UTF-8"
Howard Hinnantb4ebb0e2013-01-14 17:12:54 +000043#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 Hinnantc0d0cba2011-10-03 15:23:59 +000047#define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1"
Howard Hinnantb4ebb0e2013-01-14 17:12:54 +000048#define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2"
49#endif
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000050#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 Hinnant06d8bf62013-03-22 20:05:40 +000054#include <stdio.h>
55#include <stdlib.h>
56#include <string>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070057#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
58#include <io.h> // _mktemp
Eric Fiselier682132b2014-08-19 17:52:40 +000059#else
60#include <unistd.h> // close
Howard Hinnantae2b90b2013-10-06 21:14:05 +000061#endif
Howard Hinnant06d8bf62013-03-22 20:05:40 +000062
Jonathan Roelofs2f2daa12014-12-11 20:56:40 +000063#if defined(_NEWLIB_VERSION) && defined(__STRICT_ANSI__)
64// Newlib provies this, but in the header it's under __STRICT_ANSI__
65extern "C" {
66 int mkstemp(char*);
67}
68#endif
69
Dan Albert1d4a1ed2016-05-25 22:36:09 -070070#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
Howard Hinnant06d8bf62013-03-22 20:05:40 +000071inline
Dan Albert1d4a1ed2016-05-25 22:36:09 -070072std::string
73get_temp_file_name()
Howard Hinnant06d8bf62013-03-22 20:05:40 +000074{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070075#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
76 char Path[MAX_PATH+1];
77 char FN[MAX_PATH+1];
Eric Fiselier7aa38062016-04-29 01:22:16 +000078 do { } while (0 == GetTempPath(MAX_PATH+1, Path));
79 do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN));
80 return FN;
Howard Hinnantae2b90b2013-10-06 21:14:05 +000081#else
Jonathan Roelofs6f10d472014-08-19 13:56:56 +000082 std::string Name;
83 int FD = -1;
84 do {
Dan Albert1bd299a2015-02-13 03:02:28 +000085 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 Roelofs6f10d472014-08-19 13:56:56 +000092 close(FD);
93 return Name;
Howard Hinnant06d8bf62013-03-22 20:05:40 +000094#endif
Howard Hinnant06d8bf62013-03-22 20:05:40 +000095}
Dan Albert1d4a1ed2016-05-25 22:36:09 -070096#endif // _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
Howard Hinnant06d8bf62013-03-22 20:05:40 +000097
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000098#endif // PLATFORM_SUPPORT_H