Skip to content

Commit ca26b9b

Browse files
committed
fix macos/alpine
1 parent b6883d3 commit ca26b9b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/strict_fstream.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fstream>
55
#include <cstring>
66
#include <string>
7+
#include <vector>
78

89
/**
910
* This namespace defines wrappers for std::ifstream, std::ofstream, and
@@ -33,22 +34,28 @@ namespace strict_fstream
3334

3435
// Non-gnu variants of strerror_* don't necessarily null-terminate if
3536
// truncating, so we have to do things manually.
36-
inline std::string &trim_to_null(std::string &buff)
37+
inline std::string trim_to_null(const std::vector<char> &buff)
3738
{
38-
const std::string::size_type pos = buff.find('\0');
39+
std::string ret(buff.begin(), buff.end());
40+
41+
const std::string::size_type pos = ret.find('\0');
3942
if (pos == std::string::npos) {
40-
buff += " [...]"; // it has been truncated
43+
ret += " [...]"; // it has been truncated
4144
} else {
42-
buff.resize(pos);
45+
ret.resize(pos);
4346
}
44-
return buff;
47+
return ret;
4548
}
4649

47-
/// Overload of error-reporting function, to enable use with VS.
48-
/// Ref: http://stackoverflow.com/a/901316/717706
50+
/// Overload of error-reporting function, to enable use with VS and non-GNU
51+
/// POSIX libc's
52+
/// Ref:
53+
/// - http://stackoverflow.com/a/901316/717706
4954
static std::string strerror()
5055
{
51-
std::string buff(256, '\0');
56+
// Can't use std::string since we're pre-C++17
57+
std::vector<char> buff(256, '\0');
58+
5259
#ifdef _WIN32
5360
// Since strerror_s might set errno itself, we need to store it.
5461
const int err_num = errno;

0 commit comments

Comments
 (0)