Include fmt 11.0.2
[openal-soft.git] / fmt-11.0.2 / test / util.cc
bloba1b992b8c7b234970541fb04da722c9b0ea67f5b
1 // Formatting library for C++ - test utilities
2 //
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
5 //
6 // For the license information refer to format.h.
8 #include "util.h"
10 #include <cstring>
12 const char* const file_content = "Don't panic!";
14 fmt::buffered_file open_buffered_file(FILE** fp) {
15 #if FMT_USE_FCNTL
16 auto pipe = fmt::pipe();
17 pipe.write_end.write(file_content, std::strlen(file_content));
18 pipe.write_end.close();
19 fmt::buffered_file f = pipe.read_end.fdopen("r");
20 if (fp) *fp = f.get();
21 #else
22 fmt::buffered_file f("test-file", "w");
23 fputs(file_content, f.get());
24 if (fp) *fp = f.get();
25 #endif
26 return f;
29 std::locale do_get_locale(const char* name) {
30 try {
31 return std::locale(name);
32 } catch (const std::runtime_error&) {
34 return std::locale::classic();
37 std::locale get_locale(const char* name, const char* alt_name) {
38 auto loc = do_get_locale(name);
39 if (loc == std::locale::classic() && alt_name)
40 loc = do_get_locale(alt_name);
41 #ifdef __OpenBSD__
42 // Locales are not working in OpenBSD:
43 // https://github.com/fmtlib/fmt/issues/3670.
44 loc = std::locale::classic();
45 #endif
46 if (loc == std::locale::classic())
47 fmt::print(stderr, "{} locale is missing.\n", name);
48 return loc;