This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository e16.

View the commit online.

commit bc43570195f931f0a936065ea6dbfb954be68f6d
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Sun Dec 17 18:59:21 2023 +0100

    eesh: Eliminate need for non-blocking stdin
---
 eesh/main.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/eesh/main.c b/eesh/main.c
index 5c7a43ea..b2376900 100644
--- a/eesh/main.c
+++ b/eesh/main.c
@@ -22,7 +22,6 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #include "config.h"
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -34,7 +33,7 @@
 Display        *disp;
 
 static char     buf[10240];
-static int      stdin_state;
+static int      nin;            // Bytes in buffer
 static Client  *e;
 
 static void
@@ -52,37 +51,45 @@ process_line(char *line)
 static void
 stdin_state_setup(void)
 {
-    stdin_state = fcntl(0, F_GETFL, 0);
-    fcntl(0, F_SETFL, O_NONBLOCK);
 }
 
 static void
 stdin_state_restore(void)
 {
-    fcntl(0, F_SETFL, stdin_state);
 }
 
 static void
 stdin_read(void)
 {
-    static int      j = 0;
-    int             k, ret;
+    int             nr;
+    char           *p;
 
-    k = 0;
-    while ((ret = read(0, &(buf[j]), 1) > 0))
+    nr = read(STDIN_FILENO, buf + nin, sizeof(buf) - 1 - nin);
+    if (nr <= 0)
+        exit(0);
+    nin += nr;
+    buf[nin] = '\0';
+
+    for (;;)
     {
-        k = 1;
-        if (buf[j] == '\n')
+        p = strchr(buf, '\n');
+        if (!p)
+            break;
+
+        *p++ = '\0';            // Terminate line at \n
+
+        process_line(buf);
+        if (*p == '\0')
         {
-            buf[j] = 0;
-            if (strlen(buf) > 0)
-                process_line(buf);
-            j = -1;
+            nin = 0;            // No more input
+            break;
         }
-        j++;
+
+        // Move remaining data to start of buffer
+        nr = p - buf;
+        nin -= nr;
+        memmove(buf, buf + nr, nin);
     }
-    if ((ret < 0) || ((k == 0) && (ret == 0)))
-        exit(0);
 }
 
 int
@@ -206,7 +213,7 @@ main(int argc, char **argv)
 
         FD_ZERO(&fd);
         if (!command)
-            FD_SET(0, &fd);
+            FD_SET(STDIN_FILENO, &fd);
         FD_SET(ConnectionNumber(disp), &fd);
 
         if (select(ConnectionNumber(disp) + 1, &fd, NULL, NULL, NULL) < 0)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to