summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Support/Errno.h5
-rw-r--r--llvm/unittests/Support/ErrnoTest.cpp3
2 files changed, 6 insertions, 2 deletions
diff --git a/llvm/include/llvm/Support/Errno.h b/llvm/include/llvm/Support/Errno.h
index 35dc1ea7cf8..8069c3639df 100644
--- a/llvm/include/llvm/Support/Errno.h
+++ b/llvm/include/llvm/Support/Errno.h
@@ -34,9 +34,10 @@ template <typename FailT, typename Fun, typename... Args>
inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
const Args &... As) -> decltype(F(As...)) {
decltype(F(As...)) Res;
- do
+ do {
+ errno = 0;
Res = F(As...);
- while (Res == Fail && errno == EINTR);
+ } while (Res == Fail && errno == EINTR);
return Res;
}
diff --git a/llvm/unittests/Support/ErrnoTest.cpp b/llvm/unittests/Support/ErrnoTest.cpp
index 67f834a938d..701ac960825 100644
--- a/llvm/unittests/Support/ErrnoTest.cpp
+++ b/llvm/unittests/Support/ErrnoTest.cpp
@@ -33,4 +33,7 @@ TEST(ErrnoTest, RetryAfterSignal) {
std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
EXPECT_EQ(47, *P);
+
+ errno = EINTR;
+ EXPECT_EQ(-1, RetryAfterSignal(-1, [] { return -1; }));
}
OpenPOWER on IntegriCloud