mirror of
https://github.com/javalsai/lidm.git
synced 2025-09-07 13:31:40 +02:00
chore: dry and modularize a bit
This commit is contained in:
13
src/util.c
13
src/util.c
@@ -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;
|
||||
|
Reference in New Issue
Block a user