From 0bd73245309a2473ad51fd7a7301e08f7944b660 Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 9 Aug 2021 09:11:26 +0000 Subject: [PATCH] Unifdef read__fixio() to make it readable. Also, no need to clear O_NDELAY with fcntl(F_SETFL) when ioctl(FIONBIO) is called right afterwards. No functional change intended. OK martijn@ --- lib/libedit/read.c | 52 +++++++--------------------------------------- 1 file changed, 7 insertions(+), 45 deletions(-) diff --git a/lib/libedit/read.c b/lib/libedit/read.c index d2e73263e21..63dd846c196 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.44 2016/05/25 09:36:21 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.45 2021/08/09 09:11:26 schwarze Exp $ */ /* $NetBSD: read.c,v 1.100 2016/05/24 19:31:27 christos Exp $ */ /*- @@ -39,9 +39,10 @@ * read.c: Clean this junk up! This is horrible code. * Terminal read functions */ +#include + #include #include -#include #include #include #include @@ -134,55 +135,16 @@ el_read_getfn(struct el_read_t *el_read) /* read__fixio(): * Try to recover from a read error */ -/* ARGSUSED */ static int -read__fixio(int fd __attribute__((__unused__)), int e) +read__fixio(int fd, int e) { + int zero = 0; switch (e) { - case -1: /* Make sure that the code is reachable */ - -#ifdef EWOULDBLOCK - case EWOULDBLOCK: -#ifndef TRY_AGAIN -#define TRY_AGAIN -#endif -#endif /* EWOULDBLOCK */ - -#if defined(POSIX) && defined(EAGAIN) -#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EAGAIN: -#ifndef TRY_AGAIN -#define TRY_AGAIN -#endif -#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */ -#endif /* POSIX && EAGAIN */ - - e = 0; -#ifdef TRY_AGAIN -#if defined(F_SETFL) && defined(O_NDELAY) - if ((e = fcntl(fd, F_GETFL)) == -1) + if (ioctl(fd, FIONBIO, &zero) == -1) return -1; - - if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1) - return -1; - else - e = 1; -#endif /* F_SETFL && O_NDELAY */ - -#ifdef FIONBIO - { - int zero = 0; - - if (ioctl(fd, FIONBIO, &zero) == -1) - return -1; - else - e = 1; - } -#endif /* FIONBIO */ - -#endif /* TRY_AGAIN */ - return e ? 0 : -1; + return 0; case EINTR: return 0; -- 2.20.1