Fix problems introduced with my last change.
[deliverable/binutils-gdb.git] / gdb / ser-unix.c
index c54d9170b056c31861430e6f928102b38f668815..47b6647311c602ae5829e02e0762a04f9cf0445c 100644 (file)
@@ -1,5 +1,5 @@
 /* Serial interface for local (hardwired) serial ports on Un*x like systems
-   Copyright 1992, 1993, 1994, 1998-1999 Free Software Foundation, Inc.
+   Copyright 1992-1994, 1998-2000 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -25,9 +25,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include "terminal.h"
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
+#include "gdb_wait.h"
 #include <sys/socket.h>
 #include <sys/time.h>
 
@@ -81,7 +79,7 @@ static serial_ttystate hardwire_get_tty_state (serial_t scb);
 static int hardwire_set_tty_state (serial_t scb, serial_ttystate state);
 static int hardwire_noflush_set_tty_state (serial_t, serial_ttystate,
                                                   serial_ttystate);
-static void hardwire_print_tty_state (serial_t, serial_ttystate, struct gdb_file *);
+static void hardwire_print_tty_state (serial_t, serial_ttystate, struct ui_file *);
 static int hardwire_drain_output (serial_t);
 static int hardwire_flush_output (serial_t);
 static int hardwire_flush_input (serial_t);
@@ -228,7 +226,7 @@ hardwire_noflush_set_tty_state (serial_t scb,
 static void
 hardwire_print_tty_state (serial_t scb,
                          serial_ttystate ttystate,
-                         struct gdb_file *stream)
+                         struct ui_file *stream)
 {
   struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
   int i;
@@ -912,9 +910,9 @@ do_unix_readchar (serial_t scb, int timeout)
      each time through the loop.
 
      Also, timeout = 0 means to poll, so we just set the delta to 0, so we
-     will only go through the loop once. */
+     will only go through the loop once. timeout < 0 means to wait forever. */
 
-  delta = (timeout == 0 ? 0 : 1);
+  delta = (timeout <= 0 ? 0 : 1);
   while (1)
     {
 
@@ -930,51 +928,38 @@ do_unix_readchar (serial_t scb, int timeout)
            return SERIAL_TIMEOUT;
        }
 
-      status = ser_unix_wait_for (scb, delta);
+      status = ser_unix_wait_for (scb, timeout < 0 ? timeout : delta);
       timeout -= delta;
 
-      /* If we got a character or an error back from wait_for, then we can 
-         break from the loop before the timeout is completed. */
+      /* If we got an error back from wait_for, then we can return */
 
-      if (status != SERIAL_TIMEOUT)
-       {
-         break;
-       }
+      if (status == SERIAL_ERROR)
+        return status;
 
-      /* If we have exhausted the original timeout, then generate
-         a SERIAL_TIMEOUT, and pass it out of the loop. */
+      status = read (scb->fd, scb->buf, BUFSIZ);
 
-      else if (timeout == 0)
-       {
-         status = SERIAL_TIMEOUT;
-         break;
+      if (status <= 0)
+        {
+          if (status == 0)
+            {
+              if (timeout != 0)
+                continue;
+              else
+                return SERIAL_TIMEOUT; /* 0 chars means timeout [may need to
+                                          distinguish between EOF & timeouts
+                                          someday] */
+            }
+         else if (errno == EINTR)
+            continue;
+          else
+           return SERIAL_ERROR;        /* Got an error from read */
        }
-    }
 
-  if (status < 0)
-    return status;
-
-  while (1)
-    {
-      status = read (scb->fd, scb->buf, BUFSIZ);
-      if (status != -1 || errno != EINTR)
-       break;
-    }
-
-  if (status <= 0)
-    {
-      if (status == 0)
-       return SERIAL_TIMEOUT;  /* 0 chars means timeout [may need to
-                                  distinguish between EOF & timeouts
-                                  someday] */
-      else
-       return SERIAL_ERROR;    /* Got an error from read */
+      scb->bufcnt = status;
+      scb->bufcnt--;
+      scb->bufp = scb->buf;
+      return *scb->bufp++;
     }
-
-  scb->bufcnt = status;
-  scb->bufcnt--;
-  scb->bufp = scb->buf;
-  return *scb->bufp++;
 }
 
 /* Perform operations common to both old and new readchar. */
@@ -1046,7 +1031,7 @@ ser_unix_nop_noflush_set_tty_state (serial_t scb,
 void
 ser_unix_nop_print_tty_state (serial_t scb, 
                              serial_ttystate ttystate,
-                             struct gdb_file *stream)
+                             struct ui_file *stream)
 {
   /* Nothing to print.  */
   return;
This page took 0.025574 seconds and 4 git commands to generate.