skip_eintr_cstr

GitOrigin-RevId: e13756e7dfa4abb7452172dbedfaf73aa256bcd5
This commit is contained in:
Arseny Smirnov 2018-01-29 13:28:56 +03:00 committed by levlam
parent 3f058aff60
commit 614c3cffd7
2 changed files with 11 additions and 2 deletions

View File

@ -180,11 +180,20 @@ class Fd {
template <class F>
auto skip_eintr(F &&f) {
decltype(f()) res;
static_assert(std::is_integral<decltype(res)>::value, "integral type expected");
do {
res = f();
} while (res < 0 && errno == EINTR);
return res;
}
template <class F>
auto skip_eintr_cstr(F &&f) {
char *res;
do {
res = f();
} while (res == nullptr && errno == EINTR);
return res;
}
#endif
template <class FdT>

View File

@ -84,7 +84,7 @@ Status rename(CSlice from, CSlice to) {
Result<string> realpath(CSlice slice, bool ignore_access_denied) {
char full_path[PATH_MAX + 1];
string res;
char *err = skip_eintr([&] { return ::realpath(slice.c_str(), full_path); });
char *err = skip_eintr_cstr([&] { return ::realpath(slice.c_str(), full_path); });
if (err != full_path) {
if (ignore_access_denied && errno == EACCES) {
res = slice.str();
@ -201,7 +201,7 @@ Result<string> mkdtemp(CSlice dir, Slice prefix) {
dir_pattern.append(prefix.begin(), prefix.size());
dir_pattern += "XXXXXX";
char *result = skip_eintr([&] { return ::mkdtemp(&dir_pattern[0]); });
char *result = skip_eintr_cstr([&] { return ::mkdtemp(&dir_pattern[0]); });
if (result == nullptr) {
return OS_ERROR(PSLICE() << "Can't create temporary directory \"" << dir_pattern << '"');
}