• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include <cstring>
10 
increment(char * s)11 void increment(char* s) {
12   for (int i = static_cast<int>(std::strlen(s)) - 1; i >= 0; --i) {
13     if (s[i] != '9') {
14       ++s[i];
15       break;
16     }
17     s[i] = '0';
18   }
19 }
20 
get_system_error(int error_code)21 std::string get_system_error(int error_code) {
22 #if defined(__MINGW32__) || !defined(_WIN32)
23   return strerror(error_code);
24 #else
25   enum { BUFFER_SIZE = 200 };
26   char buffer[BUFFER_SIZE];
27   if (strerror_s(buffer, BUFFER_SIZE, error_code))
28     throw std::exception("strerror_s failed");
29   return buffer;
30 #endif
31 }
32 
33 const char* const FILE_CONTENT = "Don't panic!";
34 
open_buffered_file(FILE ** fp)35 fmt::buffered_file open_buffered_file(FILE** fp) {
36 #if FMT_USE_FCNTL
37   fmt::file read_end, write_end;
38   fmt::file::pipe(read_end, write_end);
39   write_end.write(FILE_CONTENT, std::strlen(FILE_CONTENT));
40   write_end.close();
41   fmt::buffered_file f = read_end.fdopen("r");
42   if (fp) *fp = f.get();
43 #else
44   fmt::buffered_file f("test-file", "w");
45   fputs(FILE_CONTENT, f.get());
46   if (fp) *fp = f.get();
47 #endif
48   return f;
49 }
50