From f43b9ab8ab3d336a53d1e62adcd20b48757ee22c Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sun, 10 Mar 2019 19:22:08 +0100 Subject: Use std::error_code instead of strerror_r. --- .../apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp | 10 +++++----- vespalib/src/vespa/vespalib/io/fileutil.cpp | 5 ++--- vespalib/src/vespa/vespalib/util/error.cpp | 5 +++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'vespalib') diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp index 042681a90fe..7e15885270c 100644 --- a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp +++ b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp @@ -5,9 +5,9 @@ #include #include #include +#include int main(int argc, char **argv) { - char errorBuf[200]; if (argc != 2) { fprintf(stderr, "%s \n", argv[0]); return 1; @@ -15,16 +15,16 @@ int main(int argc, char **argv) { const char *fileName = argv[1]; int fh = open(fileName, O_RDONLY); if (fh == -1) { - const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "Failed opening file %s: %s\n", fileName, errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "Failed opening file %s: %s\n", fileName, ec.message().c_str()); return 2; } int retval = 0; int err = posix_fadvise(fh, 0, 0, POSIX_FADV_DONTNEED); if (err != 0) { - const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "posix_fadvise failed: %s\n", errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "posix_fadvise failed: %s\n", ec.message().c_str()); retval = 3; } close(fh); diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp index 5acde54047a..5c3cd04cbb4 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.cpp +++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp @@ -795,9 +795,8 @@ void addStat(asciistream &os, const string & name) } os << "[name=" << name; if (statres != 0) { - char errorBuf[128]; - const char *errorString = strerror_r(err, errorBuf, sizeof(errorBuf)); - os << " errno=" << err << "(\"" << errorString << "\")"; + std::error_code ec(err, std::system_category()); + os << " errno=" << err << "(\"" << ec.message() << "\")"; } else { os << " mode=" << oct << filestat.st_mode << dec << " uid=" << filestat.st_uid << " gid=" << filestat.st_gid << diff --git a/vespalib/src/vespa/vespalib/util/error.cpp b/vespalib/src/vespa/vespalib/util/error.cpp index 3c8bbd7d9e8..0bc1e896398 100644 --- a/vespalib/src/vespa/vespalib/util/error.cpp +++ b/vespalib/src/vespa/vespalib/util/error.cpp @@ -1,14 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include +#include namespace vespalib { vespalib::string getErrorString(const int osError) { - char errorBuf[128]; - return strerror_r(osError, errorBuf, sizeof(errorBuf)); + std::error_code ec(osError, std::system_category()); + return ec.message(); } vespalib::string -- cgit v1.2.3