mirror of
https://github.com/google/sentencepiece.git
synced 2024-10-26 11:38:45 +03:00
commit
ed6f832234
19
src/util.cc
19
src/util.cc
@ -263,4 +263,23 @@ bool OutputBuffer::WriteLine(absl::string_view text) {
|
||||
return Write(text) && Write("\n");
|
||||
}
|
||||
} // namespace io
|
||||
|
||||
namespace util {
|
||||
|
||||
std::string StrError(int errnum) {
|
||||
constexpr int kStrErrorSize = 1024;
|
||||
char buffer[kStrErrorSize];
|
||||
char *str = nullptr;
|
||||
#if defined(__GLIBC__) && defined(_GNU_SOURCE)
|
||||
str = strerror_r(errnum, buffer, kStrErrorSize - 1);
|
||||
#else
|
||||
strerror_r(errnum, buffer, kStrErrorSize - 1);
|
||||
str = buffer;
|
||||
#endif
|
||||
std::ostringstream os;
|
||||
os << str << " Error #" << errnum;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace sentencepiece
|
||||
|
@ -416,11 +416,7 @@ void STLDeleteElements(std::vector<T *> *vec) {
|
||||
|
||||
namespace util {
|
||||
|
||||
inline const std::string StrError(int n) {
|
||||
char buf[1024];
|
||||
strerror_r(n, buf, sizeof(buf) - 1);
|
||||
return std::string(buf);
|
||||
}
|
||||
std::string StrError(int errnum);
|
||||
|
||||
inline Status OkStatus() { return Status(); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user