Commit 0d908464 authored by Victor Zverovich's avatar Victor Zverovich Committed by Facebook Github Bot

Make errnoStr return std::string instead of fbstring

Summary:
The result of `errnoStr` is often converted to `std::string` so returning `fbstring` adds an extra copy. Make it return `std::string` instead. This will also allow removing dependency between `String.h` and `FBString.h`.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D20195395

fbshipit-source-id: 0dc65f1566911156be3fcb715dd105c58f2a8822
parent 8d276922
......@@ -472,7 +472,7 @@ std::string hexDump(const void* ptr, size_t size) {
// selects proper function.
FOLLY_MAYBE_UNUSED
static fbstring invoke_strerror_r(
static std::string invoke_strerror_r(
int (*strerror_r)(int, char*, size_t),
int err,
char* buf,
......@@ -482,7 +482,7 @@ static fbstring invoke_strerror_r(
// OSX/FreeBSD use EINVAL and Linux uses -1 so just check for non-zero
if (r != 0) {
return to<fbstring>(
return to<std::string>(
"Unknown error ", err, " (strerror_r failed with error ", errno, ")");
} else {
return buf;
......@@ -490,7 +490,7 @@ static fbstring invoke_strerror_r(
}
FOLLY_MAYBE_UNUSED
static fbstring invoke_strerror_r(
static std::string invoke_strerror_r(
char* (*strerror_r)(int, char*, size_t),
int err,
char* buf,
......@@ -499,7 +499,7 @@ static fbstring invoke_strerror_r(
return strerror_r(err, buf, buflen);
}
fbstring errnoStr(int err) {
std::string errnoStr(int err) {
int savedErrno = errno;
// Ensure that we reset errno upon exit.
......@@ -508,7 +508,7 @@ fbstring errnoStr(int err) {
char buf[1024];
buf[0] = '\0';
fbstring result;
std::string result;
// https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/strerror_r.3.html
// http://www.kernel.org/doc/man-pages/online/pages/man3/strerror.3.html
......@@ -518,7 +518,7 @@ fbstring errnoStr(int err) {
// with strerrorlen_s). Note strerror_r and _s have swapped args.
int r = strerror_s(buf, sizeof(buf), err);
if (r != 0) {
result = to<fbstring>(
result = to<std::string>(
"Unknown error ", err, " (strerror_r failed with error ", errno, ")");
} else {
result.assign(buf);
......
......@@ -380,11 +380,11 @@ void hexDump(const void* ptr, size_t size, OutIt out);
std::string hexDump(const void* ptr, size_t size);
/**
* Return a fbstring containing the description of the given errno value.
* Return a string containing the description of the given errno value.
* Takes care not to overwrite the actual system errno, so calling
* errnoStr(errno) is valid.
*/
fbstring errnoStr(int err);
std::string errnoStr(int err);
/*
* Split a string into a list of tokens by delimiter.
......
......@@ -57,11 +57,11 @@ class Concatenator {
// clang-format off
[[noreturn]] void throwOutputError() {
throw OutputError(folly::errnoStr(errno).toStdString());
throw OutputError(folly::errnoStr(errno));
}
[[noreturn]] void throwInputError() {
throw InputError(folly::errnoStr(errno).toStdString());
throw InputError(folly::errnoStr(errno));
}
// clang-format on
......@@ -146,13 +146,13 @@ void runEcho(
const char* sep = "";
for (auto& arg : args) {
if (printf("%s%s", sep, arg.c_str()) < 0) {
throw OutputError(folly::errnoStr(errno).toStdString());
throw OutputError(folly::errnoStr(errno));
}
sep = " ";
}
if (!options["-n"].as<bool>()) {
if (putchar('\n') == EOF) {
throw OutputError(folly::errnoStr(errno).toStdString());
throw OutputError(folly::errnoStr(errno));
}
}
} catch (const OutputError& e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment