summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@verizonmedia.com>2019-03-10 19:22:08 +0100
committerTor Egge <Tor.Egge@verizonmedia.com>2019-03-10 19:29:06 +0100
commitf43b9ab8ab3d336a53d1e62adcd20b48757ee22c (patch)
treeeb3112468034aa231e66050105cec89146b6ad69 /vespalib
parentb04e96331e800c0d8e32125f02b55fd37e1510d1 (diff)
Use std::error_code instead of strerror_r.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp5
-rw-r--r--vespalib/src/vespa/vespalib/util/error.cpp5
3 files changed, 10 insertions, 10 deletions
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 <cstring>
#include <fcntl.h>
#include <unistd.h>
+#include <system_error>
int main(int argc, char **argv) {
- char errorBuf[200];
if (argc != 2) {
fprintf(stderr, "%s <filename>\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 <vespa/vespalib/util/error.h>
+#include <system_error>
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