[haiku-commits] haiku: hrev47561 - src/add-ons/kernel/generic/tty headers/posix

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Jul 2014 21:45:07 +0200 (CEST)

hrev47561 adds 2 changesets to branch 'master'
old head: 970910c21ed82601d8e69c3963fb4d0b5133a339
new head: aec644bf854b489f05ad275c682ce60c5edb8d99
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=aec644b+%5E970910c

----------------------------------------------------------------------------

0be89c1: tty: Add bitmask ioctls TIOCMBIS and TIOCMBIC
  
  Equivalent to TIOCMSET + bitmask + TIOCMGET but with a single call.
  
  Gnokii uses that.

aec644b: tty: Don't ignore errors when setting DTR
  
  Instead we and the return value of both calls.
  
  So if any fails we return an error.

                                          [ François Revol <revol@xxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 25 insertions(+), 3 deletions(-)
headers/posix/termios.h                |  2 ++
src/add-ons/kernel/generic/tty/tty.cpp | 26 +++++++++++++++++++++++---

############################################################################

Commit:      0be89c15ee9e12e1b0d7e592010af2c2eae1d952
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0be89c1
Author:      François Revol <revol@xxxxxxx>
Date:        Wed Jul 23 19:17:27 2014 UTC

tty: Add bitmask ioctls TIOCMBIS and TIOCMBIC

Equivalent to TIOCMSET + bitmask + TIOCMGET but with a single call.

Gnokii uses that.

----------------------------------------------------------------------------

diff --git a/headers/posix/termios.h b/headers/posix/termios.h
index b56c595..3aff5b9 100644
--- a/headers/posix/termios.h
+++ b/headers/posix/termios.h
@@ -185,6 +185,8 @@ struct termios {
 #define TIOCMSET                       (TCGETA + 19)   /* does 
TCSETDTR/TCSETRTS */
 #define TIOCSBRK                       (TCGETA + 20)   /* set txd pin */
 #define TIOCCBRK                       (TCGETA + 21)   /* both are a frontend 
to TCSBRK */
+#define TIOCMBIS                       (TCGETA + 22)   /* set bits in line 
state */
+#define TIOCMBIC                       (TCGETA + 23)   /* clear bits in line 
state */
 
 /* Event codes.  Returned from TCWAITEVENT */
 #define EV_RING                        0x0001
diff --git a/src/add-ons/kernel/generic/tty/tty.cpp 
b/src/add-ons/kernel/generic/tty/tty.cpp
index 7d978e2..72d9cb9 100644
--- a/src/add-ons/kernel/generic/tty/tty.cpp
+++ b/src/add-ons/kernel/generic/tty/tty.cpp
@@ -1756,6 +1756,26 @@ tty_control(tty_cookie* cookie, uint32 op, void* buffer, 
size_t length)
                        return user_memcpy(buffer, &bits, sizeof(bits));
                }
 
+               case TIOCMBIS:
+               case TIOCMBIC:
+               {
+                       // control line state setting, we only support DTR and 
RTS
+                       int value;
+                       if (user_memcpy(&value, buffer, sizeof(value)) != B_OK)
+                               return B_BAD_ADDRESS;
+
+                       bool result = false;
+                       bool dtr = (op == TIOCMBIS);
+                       if (value & TIOCM_DTR)
+                               result = tty->service_func(tty, TTYSETDTR, 
&dtr, sizeof(dtr));
+
+                       bool rts = (op == TIOCMBIS);
+                       if (value & TIOCM_RTS)
+                               result = tty->service_func(tty, TTYSETRTS, 
&rts, sizeof(rts));
+
+                       return result ? B_OK : B_ERROR;
+               }
+
                case TIOCSBRK:
                case TIOCCBRK:
                case TCSBRK:

############################################################################

Revision:    hrev47561
Commit:      aec644bf854b489f05ad275c682ce60c5edb8d99
URL:         http://cgit.haiku-os.org/haiku/commit/?id=aec644b
Author:      François Revol <revol@xxxxxxx>
Date:        Wed Jul 23 19:24:36 2014 UTC

tty: Don't ignore errors when setting DTR

Instead we and the return value of both calls.

So if any fails we return an error.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/generic/tty/tty.cpp 
b/src/add-ons/kernel/generic/tty/tty.cpp
index 72d9cb9..e1b9b2b 100644
--- a/src/add-ons/kernel/generic/tty/tty.cpp
+++ b/src/add-ons/kernel/generic/tty/tty.cpp
@@ -1734,16 +1734,16 @@ tty_control(tty_cookie* cookie, uint32 op, void* 
buffer, size_t length)
                        if (user_memcpy(&value, buffer, sizeof(value)) != B_OK)
                                return B_BAD_ADDRESS;
 
-                       bool result = false;
+                       bool result = true;
                        bool dtr = (op == TCSETDTR  && value != 0)
                                || (op == TIOCMSET && (value & TIOCM_DTR) != 0);
                        if (op == TCSETDTR || op == TIOCMSET)
-                               result = tty->service_func(tty, TTYSETDTR, 
&dtr, sizeof(dtr));
+                               result &= tty->service_func(tty, TTYSETDTR, 
&dtr, sizeof(dtr));
 
                        bool rts = (op == TCSETRTS && value != 0)
                                || (op == TIOCMSET && (value & TIOCM_RTS) != 0);
                        if (op == TCSETRTS || op == TIOCMSET)
-                               result = tty->service_func(tty, TTYSETRTS, 
&rts, sizeof(rts));
+                               result &= tty->service_func(tty, TTYSETRTS, 
&rts, sizeof(rts));
 
                        return result ? B_OK : B_ERROR;
                }
@@ -1764,14 +1764,14 @@ tty_control(tty_cookie* cookie, uint32 op, void* 
buffer, size_t length)
                        if (user_memcpy(&value, buffer, sizeof(value)) != B_OK)
                                return B_BAD_ADDRESS;
 
-                       bool result = false;
+                       bool result = true;
                        bool dtr = (op == TIOCMBIS);
                        if (value & TIOCM_DTR)
-                               result = tty->service_func(tty, TTYSETDTR, 
&dtr, sizeof(dtr));
+                               result &= tty->service_func(tty, TTYSETDTR, 
&dtr, sizeof(dtr));
 
                        bool rts = (op == TIOCMBIS);
                        if (value & TIOCM_RTS)
-                               result = tty->service_func(tty, TTYSETRTS, 
&rts, sizeof(rts));
+                               result &= tty->service_func(tty, TTYSETRTS, 
&rts, sizeof(rts));
 
                        return result ? B_OK : B_ERROR;
                }


Other related posts:

  • » [haiku-commits] haiku: hrev47561 - src/add-ons/kernel/generic/tty headers/posix - revol