From cc7f21e735f4736bb3742a73479ec6146dacd093 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Tue, 30 Sep 2014 16:05:38 +0200 Subject: [PATCH] Various cleanup Renamed device -> tty_device. Removed hardcoded tty device name max length. Updated README. --- README | 2 +- src/include/gotty/options.h | 3 ++- src/options.c | 6 +++--- src/tty.c | 7 +++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README b/README index 8b8458a..bc0b5d2 100644 --- a/README +++ b/README @@ -19,7 +19,7 @@ (output from 'gotty --help'): - Usage: gotty [] + Usage: gotty [] Options: -b, --baudrate Baud rate (default: 115200) diff --git a/src/include/gotty/options.h b/src/include/gotty/options.h index 56c2593..e610d99 100644 --- a/src/include/gotty/options.h +++ b/src/include/gotty/options.h @@ -25,11 +25,12 @@ #include #include #include +#include /* Options */ struct option_t { - char device[256]; + char tty_device[MAXPATHLEN]; bool no_autoconnect; struct termios tio; }; diff --git a/src/options.c b/src/options.c index f8321f7..295b2f9 100644 --- a/src/options.c +++ b/src/options.c @@ -39,7 +39,7 @@ struct option_t option = void print_options_help(char *argv[]) { - printf("Usage: %s [] \n", argv[0]); + printf("Usage: %s [] \n", argv[0]); printf("\n"); printf("Options:\n"); printf(" -b, --baudrate Baud rate (default: 115200)\n"); @@ -324,9 +324,9 @@ void parse_options(int argc, char *argv[]) /* Assume first non-option is the tty device name */ if (optind < argc) - strcpy(option.device, argv[optind++]); + strcpy(option.tty_device, argv[optind++]); - if (strlen(option.device) == 0) + if (strlen(option.tty_device) == 0) { printf("Error: Missing device name.\n"); exit(EXIT_FAILURE); diff --git a/src/tty.c b/src/tty.c index 2a31a14..c71a8e4 100644 --- a/src/tty.c +++ b/src/tty.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -34,8 +35,6 @@ #include "gotty/print.h" #include "gotty/options.h" -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) - static int connected = false; struct termios new_stdout, old_stdout, old_tio; static int fd; @@ -78,7 +77,7 @@ void wait_for_tty_device(void) /* Timeout */ /* Test for device file */ - if (stat(option.device, &status) == 0) + if (stat(option.tty_device, &status) == 0) return; } } @@ -146,7 +145,7 @@ int connect_tty(void) char c_stdin[3]; /* Open tty device */ - fd = open(option.device, O_RDWR | O_NOCTTY ); + fd = open(option.tty_device, O_RDWR | O_NOCTTY ); if (fd <0) { printf("\033[300DError: %s\n\033[300D", strerror(errno));