Home | History | Annotate | Download | only in support
      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 #else
     29 #define LOCALE_en_US_UTF_8     "en_US.UTF-8"
     30 #define LOCALE_fr_FR_UTF_8     "fr_FR.UTF-8"
     31 #ifdef __linux__
     32 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO-8859-1"
     33 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO-8859-2"
     34 #else
     35 #define LOCALE_fr_CA_ISO8859_1 "fr_CA.ISO8859-1"
     36 #define LOCALE_cs_CZ_ISO8859_2 "cs_CZ.ISO8859-2"
     37 #endif
     38 #define LOCALE_ru_RU_UTF_8     "ru_RU.UTF-8"
     39 #define LOCALE_zh_CN_UTF_8     "zh_CN.UTF-8"
     40 #endif
     41 
     42 #include <stdio.h>
     43 #include <stdlib.h>
     44 #include <string>
     45 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
     46 #include <io.h> // _mktemp
     47 #else
     48 #include <unistd.h> // close
     49 #endif
     50 
     51 #if defined(_NEWLIB_VERSION) && defined(__STRICT_ANSI__)
     52 // Newlib provies this, but in the header it's under __STRICT_ANSI__
     53 extern "C" {
     54   int mkstemp(char*);
     55 }
     56 #endif
     57 
     58 inline
     59 std::string
     60 get_temp_file_name()
     61 {
     62 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
     63     char Path[MAX_PATH+1];
     64     char FN[MAX_PATH+1];
     65     do { } while (0 == GetTempPath(MAX_PATH+1, Path));
     66     do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN));
     67     return FN;
     68 #else
     69     std::string Name;
     70     int FD = -1;
     71     do {
     72         Name = "libcxx.XXXXXX";
     73         FD = mkstemp(&Name[0]);
     74         if (FD == -1 && errno == EINVAL) {
     75             perror("mkstemp");
     76             abort();
     77         }
     78     } while (FD == -1);
     79     close(FD);
     80     return Name;
     81 #endif
     82 }
     83 
     84 #endif // PLATFORM_SUPPORT_H
     85