2001-05-11 Fernando Nasser <fnasser@redhat.com>
authorFernando Nasser <fnasser@redhat.com>
Fri, 11 May 2001 18:34:13 +0000 (18:34 +0000)
committerFernando Nasser <fnasser@redhat.com>
Fri, 11 May 2001 18:34:13 +0000 (18:34 +0000)
* ser-unix.c (rate_to_code): Issue warning if baud rate is invalid.
(hardwire_setbaudrate): Set errno to EINVAL and return with error
if the conversion of the baud rate to code fails.

gdb/ChangeLog
gdb/ser-unix.c

index 1eaed0da7da8901c3890a4228c42e1b29ce18ee5..025865de3678e8f15ecd89c0fd377e230578781f 100644 (file)
@@ -1,3 +1,9 @@
+2001-05-11  Fernando Nasser  <fnasser@redhat.com>
+
+       * ser-unix.c (rate_to_code): Issue warning if baud rate is invalid.
+       (hardwire_setbaudrate): Set errno to EINVAL and return with error
+       if the conversion of the baud rate to code fails.
+
 2001-05-10  Andrew Cagney  <ac131313@redhat.com>
 
        * ui-out.h (make_cleanup_ui_out_begin_end): Declare.
index 4daf11f497357bf1a2e693d03e4520ffacaa60b9..ee17c122c78526259734a9503e1bf5ca321ab6ba 100644 (file)
@@ -741,9 +741,33 @@ rate_to_code (int rate)
   int i;
 
   for (i = 0; baudtab[i].rate != -1; i++)
-    if (rate == baudtab[i].rate)
-      return baudtab[i].code;
-
+    {
+      /* test for perfect macth. */
+      if (rate == baudtab[i].rate)
+        return baudtab[i].code;
+      else
+        {
+         /* check if it is in between valid values. */
+          if (rate < baudtab[i].rate)
+           {
+             if (i)
+               {
+                 warning ("Invalid baud rate %d.  Closest values are %d and %d.",
+                           rate, baudtab[i - 1].rate, baudtab[i].rate);
+               }
+             else
+               {
+                 warning ("Invalid baud rate %d.  Minimum value is %d.",
+                           rate, baudtab[0].rate);
+               }
+             return -1;
+           }
+        }
+    }
+  /* The requested speed was too large. */
+  warning ("Invalid baud rate %d.  Maximum value is %d.",
+            rate, baudtab[i - 1].rate);
   return -1;
 }
 
@@ -751,13 +775,22 @@ static int
 hardwire_setbaudrate (serial_t scb, int rate)
 {
   struct hardwire_ttystate state;
+  int baud_code = rate_to_code (rate);
+  
+  if (baud_code < 0)
+    {
+      /* The baud rate was not valid.
+         A warning has already been issued. */
+      errno = EINVAL;
+      return -1;
+    }
 
   if (get_tty_state (scb, &state))
     return -1;
 
 #ifdef HAVE_TERMIOS
-  cfsetospeed (&state.termios, rate_to_code (rate));
-  cfsetispeed (&state.termios, rate_to_code (rate));
+  cfsetospeed (&state.termios, baud_code);
+  cfsetispeed (&state.termios, baud_code);
 #endif
 
 #ifdef HAVE_TERMIO
@@ -766,12 +799,12 @@ hardwire_setbaudrate (serial_t scb, int rate)
 #endif
 
   state.termio.c_cflag &= ~(CBAUD | CIBAUD);
-  state.termio.c_cflag |= rate_to_code (rate);
+  state.termio.c_cflag |= baud_code;
 #endif
 
 #ifdef HAVE_SGTTY
-  state.sgttyb.sg_ispeed = rate_to_code (rate);
-  state.sgttyb.sg_ospeed = rate_to_code (rate);
+  state.sgttyb.sg_ispeed = baud_code;
+  state.sgttyb.sg_ospeed = baud_code;
 #endif
 
   return set_tty_state (scb, &state);
This page took 0.027812 seconds and 4 git commands to generate.