[Support] Clear errno before calling the function in RetryAfterSignal.
authorChandler Carruth <chandlerc@gmail.com>
Sat, 7 Jul 2018 02:46:12 +0000 (02:46 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 7 Jul 2018 02:46:12 +0000 (02:46 +0000)
commit9659a127a34402d02637e0f52bfab9ee7543fb5b
treea5f2e7b3ef63ffcb322e20cffe39606b42921231
parentecce5c95977ff018ab6e5200bb2937c6b10a7ef0
[Support] Clear errno before calling the function in RetryAfterSignal.

For certain APIs, the return value of the function does not distinguish
between failure (which populates errno) and other non-error conditions
(which do not set errno).

For example, `fgets` returns `NULL` both when an error has occurred, or
upon EOF. If `errno` is already `EINTR` for whatever reason, then
```
RetryAfterSignal(nullptr, fgets, ...);
```
on a stream that has reached EOF would infinite loop.

Fix this by setting `errno` to `0` before each attempt in
`RetryAfterSignal`.

Patch by Ricky Zhou!

Differential Revision: https://reviews.llvm.org/D48755

llvm-svn: 336479
llvm/include/llvm/Support/Errno.h
llvm/unittests/Support/ErrnoTest.cpp