Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not always set stdin to FNONBLOCK when PICO_PLATFORM=host #1334

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/host/hardware_uart/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,24 @@ void _inittty(void) {
//_tty.c_oflag &= ~ONLCR;
tcsetattr(STDIN_FILENO, TCSANOW, &_tty);

fcntl(STDIN_FILENO, F_SETFL, FNONBLOCK);
atexit(_resettty);
}

static int non_blocking_getchar(void) {
fcntl(STDIN_FILENO, F_SETFL, FNONBLOCK);

int c = getchar();

int old = fcntl(STDIN_FILENO, F_GETFL);

fcntl(STDIN_FILENO, F_SETFL, old & ~FNONBLOCK);

return c;
}

#else
void _inittty() {}
static int non_blocking_getchar(void) { return getchar(); }
#endif

typedef struct {
Expand All @@ -67,7 +79,7 @@ static int _nextchar = EOF;

static bool _peekchar() {
if (_nextchar == EOF) {
_nextchar = getchar();
_nextchar = non_blocking_getchar();
}
return _nextchar != EOF;
}
Expand Down