diff options
author | Tor Egge <Tor.Egge@verizonmedia.com> | 2019-03-10 19:22:08 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@verizonmedia.com> | 2019-03-10 19:29:06 +0100 |
commit | f43b9ab8ab3d336a53d1e62adcd20b48757ee22c (patch) | |
tree | eb3112468034aa231e66050105cec89146b6ad69 /fastos/src | |
parent | b04e96331e800c0d8e32125f02b55fd37e1510d1 (diff) |
Use std::error_code instead of strerror_r.
Diffstat (limited to 'fastos/src')
-rw-r--r-- | fastos/src/vespa/fastos/file.cpp | 14 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_file.cpp | 6 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_process.cpp | 30 |
3 files changed, 17 insertions, 33 deletions
diff --git a/fastos/src/vespa/fastos/file.cpp b/fastos/src/vespa/fastos/file.cpp index 5c4d7ce9445..aff4d1c54b5 100644 --- a/fastos/src/vespa/fastos/file.cpp +++ b/fastos/src/vespa/fastos/file.cpp @@ -328,18 +328,14 @@ FastOS_FileInterface::MakeDirIfNotPresentOrExit(const char *name) } if (statInfo._error != FastOS_StatInfo::FileNotFound) { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "Could not stat %s: %s\n", name, errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "Could not stat %s: %s\n", name, ec.message().c_str()); exit(1); } if (!FastOS_File::MakeDirectory(name)) { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "Could not mkdir(\"%s\", 0775): %s\n", name, errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "Could not mkdir(\"%s\", 0775): %s\n", name, ec.message().c_str()); exit(1); } } @@ -498,4 +494,4 @@ FastOS_DirectoryScanInterface::FastOS_DirectoryScanInterface(const char *path) FastOS_DirectoryScanInterface::~FastOS_DirectoryScanInterface() { free(_searchPath); -}
\ No newline at end of file +} diff --git a/fastos/src/vespa/fastos/unix_file.cpp b/fastos/src/vespa/fastos/unix_file.cpp index 8b01a5255de..0b144c1f423 100644 --- a/fastos/src/vespa/fastos/unix_file.cpp +++ b/fastos/src/vespa/fastos/unix_file.cpp @@ -398,10 +398,8 @@ FastOS_UNIX_File::TranslateError (const int osError) std::string FastOS_UNIX_File::getErrorString(const int osError) { - char errorBuf[100]; - const char *errorString = strerror_r(osError, errorBuf, sizeof(errorBuf)); - - return std::string(errorString); + std::error_code ec(osError, std::system_category()); + return ec.message(); } diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp index 80ad0605f78..c695c8d79a0 100644 --- a/fastos/src/vespa/fastos/unix_process.cpp +++ b/fastos/src/vespa/fastos/unix_process.cpp @@ -684,9 +684,8 @@ ForkAndExec(const char *command, break; case 127: if (error != 0) { - char errorBuf[100]; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "ERROR: Could not execve %s: %s\n", command, errorString); + std::error_code ec(error, std::system_category()); + fprintf(stderr, "ERROR: Could not execve %s: %s\n", command, ec.message().c_str()); } else fprintf(stderr, "ERROR: Could not execve %s\n", command); break; @@ -1398,16 +1397,12 @@ bool FastOS_UNIX_ProcessStarter::CreateSocketPairs () _mainSocketDescr = fileDescriptors[1]; rc = true; } else { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "socketpair() failed: %s\n", errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "socketpair() failed: %s\n", ec.message().c_str()); } } else { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "socketpair() failed: %s\n", errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "socketpair() failed: %s\n", ec.message().c_str()); } return rc; } @@ -1457,17 +1452,12 @@ bool FastOS_UNIX_ProcessStarter::Start () rc = true; } } else { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "could not fork(): %s\n", errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "could not fork(): %s\n", ec.message().c_str()); } } else { - char errorBuf[100]; - int error = errno; - const char *errorString = strerror_r(error, errorBuf, sizeof(errorBuf)); - fprintf(stderr, "could not CreateSocketPairs: %s\n", - errorString); + std::error_code ec(errno, std::system_category()); + fprintf(stderr, "could not CreateSocketPairs: %s\n", ec.message().c_str()); } return rc; } |