This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Fix for errant tcgetattr() behavior


Way back in 02/01/2003, a patch of mine was applied that enhanced tcsetattr() to handle setting baud rate B0 correctly (ie. dropping DTR, leave actual baud rate alone), but added some incorrect behavior in tcgetattr(). The correct behavior, I believe, should be as follows:

1) When a baud rate of B0 is passed to tcsetattr(), it should not change the actual baud rate, but instead drop DTR.
2) In tcgetattr(), the presently set baud rate should be returned, regardless of the state of DTR.


My earlier patch broke #2. The attached patch fixes this error, and tcgetattr() now returns the correct baud rate regardless of DTR state. Thanks,

-Troy

Changelog entry:
* fhandler_serial.cc (fhandler_serial::tcgetattr): Make tcgetattr() return current baud rate regardless of current DTR state.


--- old_fhandler_serial.cc	2005-08-11 09:31:05.202669500 -0600
+++ new_fhandler_serial.cc	2005-08-11 09:38:36.104522300 -0600
@@ -908,55 +908,50 @@ fhandler_serial::tcgetattr (struct termi
   memset (t, 0, sizeof (*t));
 
   /* -------------- Baud rate ------------------ */
-
-  /* If DTR is NOT set, return B0 as our speed */
-  if (dtr != TIOCM_DTR)
-    t->c_cflag = t->c_ospeed = t->c_ispeed = B0;
-  else
-    switch (state.BaudRate)
-      {
-      case CBR_110:
+  switch (state.BaudRate)
+    {
+    case CBR_110:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B110;
 	break;
-      case CBR_300:
+    case CBR_300:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B300;
 	break;
-      case CBR_600:
+    case CBR_600:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B600;
 	break;
-      case CBR_1200:
+    case CBR_1200:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B1200;
 	break;
-      case CBR_2400:
+    case CBR_2400:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B2400;
 	break;
-      case CBR_4800:
+    case CBR_4800:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B4800;
 	break;
-      case CBR_9600:
+    case CBR_9600:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B9600;
 	break;
-      case CBR_19200:
+    case CBR_19200:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B19200;
 	break;
-      case CBR_38400:
+    case CBR_38400:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B38400;
 	break;
-      case CBR_57600:
+    case CBR_57600:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B57600;
 	break;
-      case CBR_115200:
+    case CBR_115200:
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B115200;
 	break;
-      case 230400: /* CBR_230400 - not defined */
+    case 230400: /* CBR_230400 - not defined */
 	t->c_cflag = t->c_ospeed = t->c_ispeed = B230400;
 	break;
-      default:
+    default:
 	/* Unsupported baud rate! */
 	termios_printf ("Invalid baud rate %d", state.BaudRate);
 	set_errno (EINVAL);
 	return -1;
-      }
+    }
 
   /* -------------- Byte size ------------------ */
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]