1 // Formatting library for C++ - test utilities
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
6 // For the license information refer to format.h.
12 const char* const file_content
= "Don't panic!";
14 fmt::buffered_file
open_buffered_file(FILE** fp
) {
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();
22 fmt::buffered_file
f("test-file", "w");
23 fputs(file_content
, f
.get());
24 if (fp
) *fp
= f
.get();
29 std::locale
do_get_locale(const char* name
) {
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
);
42 // Locales are not working in OpenBSD:
43 // https://github.com/fmtlib/fmt/issues/3670.
44 loc
= std::locale::classic();
46 if (loc
== std::locale::classic())
47 fmt::print(stderr
, "{} locale is missing.\n", name
);