diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2021-08-09 09:11:27 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2021-08-09 09:11:27 +0000 |
commit | 6ea9f5ccb005ce4031009a6a3fb06c98bffffdd8 (patch) | |
tree | d07816d1d43a76207f1577877fed96f63447f9c1 /lib/libedit | |
parent | 9f8b42121e3f4ab7fb370530bb2f47c8203cd30b (diff) |
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@
Diffstat (limited to 'lib/libedit')
-rw-r--r-- | lib/libedit/read.c | 52 |
1 files 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 <sys/ioctl.h> + #include <ctype.h> #include <errno.h> -#include <fcntl.h> #include <limits.h> #include <stdlib.h> #include <string.h> @@ -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; |