]> git.proxmox.com Git - ceph.git/blame - ceph/src/fmt/test/util.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / fmt / test / util.cc
CommitLineData
11fdf7f2
TL
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.
7
8#include "util.h"
f67539c2 9
11fdf7f2
TL
10#include <cstring>
11
20effc67 12const char* const file_content = "Don't panic!";
11fdf7f2 13
9f95a23c 14fmt::buffered_file open_buffered_file(FILE** fp) {
f67539c2 15#if FMT_USE_FCNTL
11fdf7f2
TL
16 fmt::file read_end, write_end;
17 fmt::file::pipe(read_end, write_end);
20effc67 18 write_end.write(file_content, std::strlen(file_content));
11fdf7f2
TL
19 write_end.close();
20 fmt::buffered_file f = read_end.fdopen("r");
9f95a23c 21 if (fp) *fp = f.get();
f67539c2
TL
22#else
23 fmt::buffered_file f("test-file", "w");
20effc67 24 fputs(file_content, f.get());
f67539c2
TL
25 if (fp) *fp = f.get();
26#endif
11fdf7f2
TL
27 return f;
28}
20effc67
TL
29
30std::locale do_get_locale(const char* name) {
31 try {
32 return std::locale(name);
33 } catch (const std::runtime_error&) {
34 }
35 return std::locale::classic();
36}
37
38std::locale get_locale(const char* name, const char* alt_name) {
39 auto loc = do_get_locale(name);
40 if (loc == std::locale::classic() && alt_name) {
41 loc = do_get_locale(alt_name);
42 }
43 if (loc == std::locale::classic())
44 fmt::print(stderr, "{} locale is missing.\n", name);
45 return loc;
46}