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