Stop using a while loop for code that runs at most once,
authorschwarze <schwarze@openbsd.org>
Fri, 13 Aug 2021 10:21:25 +0000 (10:21 +0000)
committerschwarze <schwarze@openbsd.org>
Fri, 13 Aug 2021 10:21:25 +0000 (10:21 +0000)
and garbage collect an automatic variable that is no longer needed
and a comment that was probably contributed by Capt. Obvious.
No functional change.

OK millert@ martijn@

lib/libedit/read.c

index cd1b57f..8c00c66 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: read.c,v 1.48 2021/08/12 10:31:15 schwarze Exp $      */
+/*     $OpenBSD: read.c,v 1.49 2021/08/13 10:21:25 schwarze Exp $      */
 /*     $NetBSD: read.c,v 1.100 2016/05/24 19:31:27 christos Exp $      */
 
 /*-
@@ -209,13 +209,13 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, wchar_t *ch)
 static int
 read_char(EditLine *el, wchar_t *cp)
 {
-       ssize_t num_read;
        char cbuf[MB_LEN_MAX];
        int cbp = 0;
 
  again:
        el->el_signal->sig_no = 0;
-       while ((num_read = read(el->el_infd, cbuf + cbp, 1)) == -1) {
+       switch (read(el->el_infd, cbuf + cbp, 1)) {
+       case -1:
                if (errno == EINTR) {
                        switch (el->el_signal->sig_no) {
                        case SIGCONT:
@@ -230,12 +230,11 @@ read_char(EditLine *el, wchar_t *cp)
                }
                *cp = L'\0';
                return -1;
-       }
-
-       /* Test for EOF */
-       if (num_read == 0) {
+       case 0:
                *cp = L'\0';
                return 0;
+       default:
+               break;
        }
 
        for (;;) {