From 0de21824cc013fe9583b1f9839307e60f63bd6ed Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 18 Sep 2021 13:05:28 -0400 Subject: [PATCH] [input] return error once we've emptied ibuf and hit stdineof --- src/lib/in.c | 5 +++++ src/poc/hilodirect.c | 38 -------------------------------------- 2 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 src/poc/hilodirect.c diff --git a/src/lib/in.c b/src/lib/in.c index 0f4a37c7b..80d56e89c 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -1992,6 +1992,11 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){ } pthread_mutex_lock(&ictx->ilock); while(!ictx->ivalid){ + if(ictx->stdineof){ + pthread_mutex_unlock(&ictx->ilock); + logwarn("read eof on stdin\n"); + return -1; + } if(ts == NULL){ pthread_cond_wait(&ictx->icond, &ictx->ilock); }else{ diff --git a/src/poc/hilodirect.c b/src/poc/hilodirect.c deleted file mode 100644 index 7cf4eee84..000000000 --- a/src/poc/hilodirect.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -int main(void){ - srand(time(NULL)); // gross - long guess, secret = rand(); - struct ncdirect* n = ncdirect_core_init(NULL, stdout, NCDIRECT_OPTION_INHIBIT_CBREAK); - if(n == NULL){ - return EXIT_FAILURE; - } - int r = 0; - do{ - if(!(r |= (ncdirect_set_fg_default(n)))){ - if(!(r |= (printf("Guess the long: ") < 0))){ - if(!(r |= fflush(stdout))){ - int rargs = scanf("%ld", &guess); // super shitty to the max - if(rargs != 1){ - r = -1; - break; - } - int offoom = labs(__builtin_clzl(guess) - __builtin_clzl(secret)); - if(guess > secret){ - r |= ncdirect_set_fg_rgb8(n, 0x40, 0x80, offoom * 6); - r |= (printf("\tLOL jabronies guess %ld. Too high!\n", guess) < 0); - }else if(guess < secret){ - r |= ncdirect_set_fg_rgb8(n, offoom * 6, 0x80, 0x40); - r |= (printf("\tSpineless worm! %ld? Too low!\n", guess) < 0); - } - } - } - } - }while(!r && guess != secret); - if(r || printf("You enjoy 20/20 vision into the minds of antimen!\n") < 0){ - ncdirect_stop(n); - return EXIT_FAILURE; - } - return ncdirect_stop(n) ? EXIT_FAILURE : EXIT_SUCCESS; -}