Menu

#2 Portability for setting baud rate  Edit

v0.29
closed
0.2.0
1
2016-06-25
2012-04-22
No

From a04cbf4ec4009b8690a823049564df2cda120d93 Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson gnu@gisladisker.se
Date: Sun, 22 Apr 2012 03:43:19 +0200
Subject: [PATCH] Portability for setting baud rate.

Portability needs cfsetispeed() and cfsetospeed().
Succesful on OpenSolaris, OpenBSD, FreeBSD, NetBSD,
and DragonFly BSD. Clean compilation on all after
inclusion of <strings.h> to get bzero() on Solaris.


 ttylog.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

 diff --git a/ttylog.c b/ttylog.c
 index 1bc1fae..f7817ee 100644
 --- a/ttylog.c
 +++ b/ttylog.c
@@ -21,6 +21,7 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -125,10 +126,13 @@ main (int argc, char *argv[])
 tcgetattr (fd, &oldtio);     /* save current serial port settings */
 bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */

- newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
+ newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
  newtio.c_iflag = IGNPAR | IGNCR;
  newtio.c_oflag = 0;
  newtio.c_lflag = ICANON;
+ /* Only truly portable method of setting speed. */
+ cfsetispeed (&newtio, BAUD_B[baud]);
+ cfsetospeed (&newtio, BAUD_B[baud]);

  tcflush (fd, TCIFLUSH);
  tcsetattr (fd, TCSANOW, &newtio);
-- 
1.7.9.5

Discussion

  • Robert James Clay

    • Description has changed:

    Diff:

    --- old 
    +++ new 
    @@ -8,35 +8,35 @@
     and DragonFly BSD. Clean compilation on all after
     inclusion of <strings.h> to get bzero() on Solaris.
     ---
    - ttylog.c |    6 +++++-
    - 1 file changed, 5 insertions(+), 1 deletion(-)
    +    ttylog.c |    6 +++++-
    +    1 file changed, 5 insertions(+), 1 deletion(-)
    
    -diff --git a/ttylog.c b/ttylog.c
    -index 1bc1fae..f7817ee 100644
    ---- a/ttylog.c
    -+++ b/ttylog.c
    -@@ -21,6 +21,7 @@
    - #include <stdio.h>
    - #include <stdlib.h>
    - #include <string.h>
    -+#include <strings.h>
    - #include <unistd.h>
    - #include <sys/types.h>
    - #include <fcntl.h>
    -@@ -125,10 +126,13 @@ main (int argc, char *argv[])
    -   tcgetattr (fd, &oldtio);     /* save current serial port settings */
    -   bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    - 
    --  newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
    -+  newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    -   newtio.c_iflag = IGNPAR | IGNCR;
    -   newtio.c_oflag = 0;
    -   newtio.c_lflag = ICANON;
    -+  /* Only truly portable method of setting speed. */
    -+  cfsetispeed (&newtio, BAUD_B[baud]);
    -+  cfsetospeed (&newtio, BAUD_B[baud]);
    - 
    -   tcflush (fd, TCIFLUSH);
    -   tcsetattr (fd, TCSANOW, &newtio);
    --- 
    -1.7.9.5
    +    diff --git a/ttylog.c b/ttylog.c
    +    index 1bc1fae..f7817ee 100644
    +    --- a/ttylog.c
    +    +++ b/ttylog.c
    +   @@ -21,6 +21,7 @@ 
    +    #include <stdio.h>
    +    #include <stdlib.h>
    +    #include <string.h>
    +   +#include <strings.h>
    +    #include <unistd.h>
    +    #include <sys/types.h>
    +    #include <fcntl.h>
    +   @@ -125,10 +126,13 @@ main (int argc, char *argv[])
    +    tcgetattr (fd, &oldtio);     /* save current serial port settings */
    +    bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    + 
    +   - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
    +   + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    +     newtio.c_iflag = IGNPAR | IGNCR;
    +     newtio.c_oflag = 0;
    +     newtio.c_lflag = ICANON;
    +   + /* Only truly portable method of setting speed. */
    +   + cfsetispeed (&newtio, BAUD_B[baud]);
    +   + cfsetospeed (&newtio, BAUD_B[baud]);
    + 
    +     tcflush (fd, TCIFLUSH);
    +     tcsetattr (fd, TCSANOW, &newtio);
    +   -- 
    +   1.7.9.5
    
    • Description has changed:

    Diff:

    --- old 
    +++ new 
    @@ -7,36 +7,37 @@
     Succesful on OpenSolaris, OpenBSD, FreeBSD, NetBSD,
     and DragonFly BSD. Clean compilation on all after
     inclusion of <strings.h> to get bzero() on Solaris.
    ----
    +--- `
         ttylog.c |    6 +++++-
         1 file changed, 5 insertions(+), 1 deletion(-)
    
         diff --git a/ttylog.c b/ttylog.c
         index 1bc1fae..f7817ee 100644
         --- a/ttylog.c
         +++ b/ttylog.c
        @@ -21,6 +21,7 @@ 
         #include <stdio.h>
         #include <stdlib.h>
         #include <string.h>
        +#include <strings.h>
         #include <unistd.h>
         #include <sys/types.h>
         #include <fcntl.h>
        @@ -125,10 +126,13 @@ main (int argc, char *argv[])
         tcgetattr (fd, &oldtio);     /* save current serial port settings */
         bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    
        - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
        + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
          newtio.c_iflag = IGNPAR | IGNCR;
          newtio.c_oflag = 0;
          newtio.c_lflag = ICANON;
        + /* Only truly portable method of setting speed. */
        + cfsetispeed (&newtio, BAUD_B[baud]);
        + cfsetospeed (&newtio, BAUD_B[baud]);
    
          tcflush (fd, TCIFLUSH);
          tcsetattr (fd, TCSANOW, &newtio);
        -- 
        1.7.9.5
    +`
    
    • Description has changed:

    Diff:

    --- old 
    +++ new 
    @@ -10,32 +10,32 @@
     --- `
         ttylog.c |    6 +++++-
         1 file changed, 5 insertions(+), 1 deletion(-)
    -
    +``
         diff --git a/ttylog.c b/ttylog.c
         index 1bc1fae..f7817ee 100644
         --- a/ttylog.c
         +++ b/ttylog.c
        @@ -21,6 +21,7 @@ 
         #include <stdio.h>
         #include <stdlib.h>
         #include <string.h>
        +#include <strings.h>
         #include <unistd.h>
         #include <sys/types.h>
         #include <fcntl.h>
        @@ -125,10 +126,13 @@ main (int argc, char *argv[])
         tcgetattr (fd, &oldtio);     /* save current serial port settings */
         bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    - 
    +`` 
        - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
        + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
          newtio.c_iflag = IGNPAR | IGNCR;
          newtio.c_oflag = 0;
          newtio.c_lflag = ICANON;
        + /* Only truly portable method of setting speed. */
        + cfsetispeed (&newtio, BAUD_B[baud]);
        + cfsetospeed (&newtio, BAUD_B[baud]);
    - 
    +`` 
          tcflush (fd, TCIFLUSH);
          tcsetattr (fd, TCSANOW, &newtio);
        -- 
    
     
  • Robert James Clay

    • Description has changed:

    Diff:

    --- old 
    +++ new 
    @@ -7,37 +7,37 @@
     Succesful on OpenSolaris, OpenBSD, FreeBSD, NetBSD,
     and DragonFly BSD. Clean compilation on all after
     inclusion of <strings.h> to get bzero() on Solaris.
    ---- `
    -    ttylog.c |    6 +++++-
    -    1 file changed, 5 insertions(+), 1 deletion(-)
    -``
    -    diff --git a/ttylog.c b/ttylog.c
    -    index 1bc1fae..f7817ee 100644
    -    --- a/ttylog.c
    -    +++ b/ttylog.c
    -   @@ -21,6 +21,7 @@ 
    -    #include <stdio.h>
    -    #include <stdlib.h>
    -    #include <string.h>
    -   +#include <strings.h>
    -    #include <unistd.h>
    -    #include <sys/types.h>
    -    #include <fcntl.h>
    -   @@ -125,10 +126,13 @@ main (int argc, char *argv[])
    -    tcgetattr (fd, &oldtio);     /* save current serial port settings */
    -    bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    -`` 
    -   - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
    -   + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    -     newtio.c_iflag = IGNPAR | IGNCR;
    -     newtio.c_oflag = 0;
    -     newtio.c_lflag = ICANON;
    -   + /* Only truly portable method of setting speed. */
    -   + cfsetispeed (&newtio, BAUD_B[baud]);
    -   + cfsetospeed (&newtio, BAUD_B[baud]);
    -`` 
    -     tcflush (fd, TCIFLUSH);
    -     tcsetattr (fd, TCSANOW, &newtio);
    -   -- 
    -   1.7.9.5
    -`
    +--- 
    +
    +     ttylog.c |    6 +++++-
    +     1 file changed, 5 insertions(+), 1 deletion(-)
    +
    +     diff --git a/ttylog.c b/ttylog.c
    +     index 1bc1fae..f7817ee 100644
    +     --- a/ttylog.c
    +     +++ b/ttylog.c
    +    @@ -21,6 +21,7 @@ 
    +     #include <stdio.h>
    +     #include <stdlib.h>
    +     #include <string.h>
    +    +#include <strings.h>
    +     #include <unistd.h>
    +     #include <sys/types.h>
    +     #include <fcntl.h>
    +    @@ -125,10 +126,13 @@ main (int argc, char *argv[])
    +     tcgetattr (fd, &oldtio);     /* save current serial port settings */
    +     bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    + 
    +    - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
    +    + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    +      newtio.c_iflag = IGNPAR | IGNCR;
    +      newtio.c_oflag = 0;
    +      newtio.c_lflag = ICANON;
    +    + /* Only truly portable method of setting speed. */
    +    + cfsetispeed (&newtio, BAUD_B[baud]);
    +    + cfsetospeed (&newtio, BAUD_B[baud]);
    + 
    +      tcflush (fd, TCIFLUSH);
    +      tcsetattr (fd, TCSANOW, &newtio);
    +    -- 
    +    1.7.9.5
    
     
  • Robert James Clay

    Plan to investigate adding this to version v0.2.0.

     
  • Robert James Clay

    • labels: http://www.nazi-for-sale.com --> Compatibility
    • summary: nazi uniform --> Portability for setting baud rate
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +1,43 @@
    -Mood very bad :(
    +From a04cbf4ec4009b8690a823049564df2cda120d93 Mon Sep 17 00:00:00 2001
    +From: Mats Erik Andersson <gnu@gisladisker.se>
    +Date: Sun, 22 Apr 2012 03:43:19 +0200
    +Subject: [PATCH] Portability for setting baud rate.
    +
    +Portability needs cfsetispeed() and cfsetospeed().
    +Succesful on OpenSolaris, OpenBSD, FreeBSD, NetBSD,
    +and DragonFly BSD. Clean compilation on all after
    +inclusion of <strings.h> to get bzero() on Solaris.
    +---- 
    +
    +     ttylog.c |    6 +++++-
    +     1 file changed, 5 insertions(+), 1 deletion(-)
    +
    +     diff --git a/ttylog.c b/ttylog.c
    +     index 1bc1fae..f7817ee 100644
    +     --- a/ttylog.c
    +     +++ b/ttylog.c
    +    @@ -21,6 +21,7 @@ 
    +     #include <stdio.h>
    +     #include <stdlib.h>
    +     #include <string.h>
    +    +#include <strings.h>
    +     #include <unistd.h>
    +     #include <sys/types.h>
    +     #include <fcntl.h>
    +    @@ -125,10 +126,13 @@ main (int argc, char *argv[])
    +     tcgetattr (fd, &oldtio);     /* save current serial port settings */
    +     bzero (&newtio, sizeof (newtio));    /* clear struct for new port settings */
    + 
    +    - newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
    +    + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
    +      newtio.c_iflag = IGNPAR | IGNCR;
    +      newtio.c_oflag = 0;
    +      newtio.c_lflag = ICANON;
    +    + /* Only truly portable method of setting speed. */
    +    + cfsetispeed (&newtio, BAUD_B[baud]);
    +    + cfsetospeed (&newtio, BAUD_B[baud]);
    + 
    +      tcflush (fd, TCIFLUSH);
    +      tcsetattr (fd, TCSANOW, &newtio);
    +    -- 
    +    1.7.9.5
    
    • status: --> open
    • group: --> 0.2.0
    • priority: --> 1
    • milestone: --> v0.2.0
     
  • Robert James Clay

    • status: open --> accepted
    • milestone: v0.2.0 --> BaudRate
     
  • Robert James Clay

    Change to milestone BaudRate.

     
  • Robert James Clay

    • milestone: v0.20 --> BaudRate
     
  • Robert James Clay

    • Milestone: v0.28 --> v0.29
     
  • Robert James Clay

    • status: accepted --> closed
     
  • Robert James Clay

    Released with verion 0.29.

     

Anonymous
Anonymous

Add attachments
Cancel