From c73dd807e1d70738f6e060143fd37b3ea6587f5e Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 19 Nov 2017 20:16:42 -0800 Subject: [PATCH] ErrorBase: Remove last use of sstream and iostream. (#750) --- wpilibc/src/main/native/cpp/ErrorBase.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/wpilibc/src/main/native/cpp/ErrorBase.cpp b/wpilibc/src/main/native/cpp/ErrorBase.cpp index bbb266a3a1..0642b7e8f9 100644 --- a/wpilibc/src/main/native/cpp/ErrorBase.cpp +++ b/wpilibc/src/main/native/cpp/ErrorBase.cpp @@ -10,13 +10,12 @@ #include #include #include -#include -#include #include #define WPI_ERRORS_DEFINE_STRINGS #include "WPIErrors.h" +#include "llvm/Format.h" #include "llvm/SmallString.h" #include "llvm/raw_ostream.h" @@ -53,20 +52,18 @@ void ErrorBase::ClearError() const { m_error.Clear(); } void ErrorBase::SetErrnoError(llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const { - std::string err; + llvm::SmallString<128> buf; + llvm::raw_svector_ostream err(buf); int errNo = errno; if (errNo == 0) { - err = "OK: "; - err += contextMessage; + err << "OK: " << contextMessage; } else { - std::ostringstream oss; - oss << std::strerror(errNo) << " (0x" << std::setfill('0') << std::hex - << std::uppercase << std::setw(8) << errNo << "): " << contextMessage; - err = oss.str(); + err << std::strerror(errNo) << " (" << llvm::format_hex(errNo, 10, true) + << "): " << contextMessage; } // Set the current error information for this object. - m_error.Set(-1, err, filename, function, lineNumber, this); + m_error.Set(-1, err.str(), filename, function, lineNumber, this); // Update the global error if there is not one already set. std::lock_guard mutex(_globalErrorMutex);