Files
clang-p2996/lldb/test/API/iohandler/sigint/cat.cpp
Pavel Labath a4d6de2031 [lldb] Fix TestProcessIOHandlerInterrupt.py for macos
On darwin, we don't completely suppress the signal used to interrupt the
inferior. The underlying read syscall returns EINTR, which causes premature
termination of the input loop.

Work around that by hand-rolling an EINTR-resistant version of getline.
2022-03-18 11:51:55 +01:00

29 lines
475 B
C++

#include <cstdio>
#include <string>
#include <unistd.h>
std::string getline() {
std::string result;
while (true) {
int r;
char c;
do
r = read(fileno(stdin), &c, 1);
while (r == -1 && errno == EINTR);
if (r <= 0 || c == '\n')
return result;
result += c;
}
}
void input_copy_loop() {
std::string str;
while (str = getline(), !str.empty())
printf("read: %s\n", str.c_str());
}
int main() {
input_copy_loop();
return 0;
}