Unifdef read__fixio() to make it readable.
authorschwarze <schwarze@openbsd.org>
Mon, 9 Aug 2021 09:11:26 +0000 (09:11 +0000)
committerschwarze <schwarze@openbsd.org>
Mon, 9 Aug 2021 09:11:26 +0000 (09:11 +0000)
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

index d2e7326..63dd846 100644 (file)
@@ -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 $      */
 
 /*-
  * 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;