]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_baudrate.c
ncurses 5.6 - patch 20080621
[ncurses.git] / ncurses / tinfo / lib_baudrate.c
index 5238924143672edd2407c3ef48f4003673324044..28405bee3336b1d4186dcfe2583328eeb7e3808a 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998,2000,2002 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,7 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
 /*
  ****************************************************************************/
 
 /*
@@ -39,6 +40,9 @@
 #include <curses.priv.h>
 #include <term.h>              /* cur_term, pad_char */
 #include <termcap.h>           /* ospeed */
 #include <curses.priv.h>
 #include <term.h>              /* cur_term, pad_char */
 #include <termcap.h>           /* ospeed */
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#endif
 
 /*
  * These systems use similar header files, which define B1200 as 1200, etc.,
 
 /*
  * These systems use similar header files, which define B1200 as 1200, etc.,
@@ -46,7 +50,7 @@
  * of the indices up to B115200 fit nicely in a 'short', allowing us to retain
  * ospeed's type for compatibility.
  */
  * of the indices up to B115200 fit nicely in a 'short', allowing us to retain
  * ospeed's type for compatibility.
  */
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#if (defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || defined(__NetBSD__) || defined(__OpenBSD__)
 #undef B0
 #undef B50
 #undef B75
 #undef B0
 #undef B50
 #undef B75
@@ -76,7 +80,7 @@
 #undef USE_OLD_TTY
 #endif /* USE_OLD_TTY */
 
 #undef USE_OLD_TTY
 #endif /* USE_OLD_TTY */
 
-MODULE_ID("$Id: lib_baudrate.c,v 1.22 2002/01/19 23:07:53 Andrey.A.Chernov Exp $")
+MODULE_ID("$Id: lib_baudrate.c,v 1.26 2008/06/21 20:46:10 tom Exp $")
 
 /*
  *     int
 
 /*
  *     int
@@ -141,16 +145,20 @@ static struct speed const speeds[] =
 NCURSES_EXPORT(int)
 _nc_baudrate(int OSpeed)
 {
 NCURSES_EXPORT(int)
 _nc_baudrate(int OSpeed)
 {
+#if !USE_REENTRANT
     static int last_OSpeed;
     static int last_baudrate;
     static int last_OSpeed;
     static int last_baudrate;
+#endif
 
 
-    int result;
+    int result = ERR;
     unsigned i;
 
     unsigned i;
 
+#if !USE_REENTRANT
     if (OSpeed == last_OSpeed) {
        result = last_baudrate;
     if (OSpeed == last_OSpeed) {
        result = last_baudrate;
-    } else {
-       result = ERR;
+    }
+#endif
+    if (result == ERR) {
        if (OSpeed >= 0) {
            for (i = 0; i < SIZEOF(speeds); i++) {
                if (speeds[i].s == OSpeed) {
        if (OSpeed >= 0) {
            for (i = 0; i < SIZEOF(speeds); i++) {
                if (speeds[i].s == OSpeed) {
@@ -159,7 +167,12 @@ _nc_baudrate(int OSpeed)
                }
            }
        }
                }
            }
        }
-       last_baudrate = result;
+#if !USE_REENTRANT
+       if (OSpeed == last_OSpeed) {
+           last_OSpeed = OSpeed;
+           last_baudrate = result;
+       }
+#endif
     }
     return (result);
 }
     }
     return (result);
 }
@@ -204,19 +217,22 @@ baudrate(void)
     }
 #endif
 
     }
 #endif
 
+    if (cur_term != 0) {
 #ifdef USE_OLD_TTY
 #ifdef USE_OLD_TTY
-    result = cfgetospeed(&cur_term->Nttyb);
-    ospeed = _nc_ospeed(result);
+       result = cfgetospeed(&cur_term->Nttyb);
+       ospeed = _nc_ospeed(result);
 #else /* !USE_OLD_TTY */
 #ifdef TERMIOS
 #else /* !USE_OLD_TTY */
 #ifdef TERMIOS
-    ospeed = cfgetospeed(&cur_term->Nttyb);
+       ospeed = cfgetospeed(&cur_term->Nttyb);
 #else
 #else
-    ospeed = cur_term->Nttyb.sg_ospeed;
+       ospeed = cur_term->Nttyb.sg_ospeed;
 #endif
 #endif
-    result = _nc_baudrate(ospeed);
+       result = _nc_baudrate(ospeed);
 #endif
 #endif
-    if (cur_term != 0)
        cur_term->_baudrate = result;
        cur_term->_baudrate = result;
+    } else {
+       result = ERR;
+    }
 
     returnCode(result);
 }
 
     returnCode(result);
 }