chore: dry and modularize a bit

This commit is contained in:
2025-07-04 01:41:56 +02:00
parent f5445248d3
commit 9f905622a2
3 changed files with 39 additions and 46 deletions

View File

@@ -1,3 +1,5 @@
#include <asm-generic/errno-base.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -53,6 +55,17 @@ void read_press(u_char* length, char* out) {
}
}
bool read_press_nb(u_char* length, char* out, struct timeval* tv) {
fd_set fds;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
int ret = select(STDIN_FILENO + 1, &fds, NULL, NULL, tv);
if ((ret < 0 && errno == EINTR) || ret == 0) return false;
read_press(length, out);
return true;
}
// https://stackoverflow.com/a/48040042
static int selret_magic() {
fd_set set;