From a51bf815aa1d9a64d04888b95db9d02cb27be763 Mon Sep 17 00:00:00 2001 From: fujr Date: Tue, 22 Oct 2024 23:34:39 +0800 Subject: [PATCH] tom_modem: fix ld error --- application/tom_modem/src/main.c | 6 +++++- application/tom_modem/src/main.h | 13 ++++++------- application/tom_modem/src/utils.c | 7 +++++-- application/tom_modem/src/utils.h | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/application/tom_modem/src/main.c b/application/tom_modem/src/main.c index c74d944..bf3775a 100644 --- a/application/tom_modem/src/main.c +++ b/application/tom_modem/src/main.c @@ -11,8 +11,12 @@ #include #include +FILE *fdi; // file descriptor for input +FILE *fdo; // file descriptor for output +int tty_fd; // file descriptor for tty device - +PROFILE_T s_profile; // global profile +char *self_name; // program name void _timeout(int signo) { err_msg("Exit with Signal %d", signo); diff --git a/application/tom_modem/src/main.h b/application/tom_modem/src/main.h index 4182697..6a95996 100644 --- a/application/tom_modem/src/main.h +++ b/application/tom_modem/src/main.h @@ -14,13 +14,12 @@ #define DEFAULT_TIMEOUT 3 // - -FILE *fdi; // file descriptor for input -FILE *fdo; // file descriptor for output -int tty_fd; // file descriptor for tty device - -PROFILE_T s_profile; // global profile -char *self_name; // program name +extern FILE *fdi; // file descriptor for input +extern FILE *fdo; // file descriptor for output +extern int tty_fd; // file descriptor for tty device +extern PROFILE_T s_profile; // global profile +extern char *self_name; // program name +extern struct termios oldtio; // old tty setting extern int at(PROFILE_T *profile); diff --git a/application/tom_modem/src/utils.c b/application/tom_modem/src/utils.c index 9bf323e..558844a 100644 --- a/application/tom_modem/src/utils.c +++ b/application/tom_modem/src/utils.c @@ -1,5 +1,6 @@ #include "utils.h" #include "pdu_lib/pdu.h" +struct termios oldtio; int match_option(char *option_name) { @@ -164,7 +165,8 @@ int open_tty_device(PROFILE_T *profile) } tcflush(tty_fd, TCIOFLUSH); atexit(clean_up); - close(tty_fd); + if (tty_fd >= 0) + close(tty_fd); tty_fd = open(profile->tty_dev, O_RDWR | O_NOCTTY); fdi = fdopen(tty_fd, "r"); fdo = fdopen(tty_fd, "w"); @@ -305,7 +307,8 @@ static void clean_up() } dbg_msg("Clean up success"); tcflush(tty_fd, TCIOFLUSH); - close(tty_fd); + // if (tty_fd >= 0) + // close(tty_fd); } static void escape_json(char *input, char *output) diff --git a/application/tom_modem/src/utils.h b/application/tom_modem/src/utils.h index d93a2c7..8758c1b 100644 --- a/application/tom_modem/src/utils.h +++ b/application/tom_modem/src/utils.h @@ -9,7 +9,7 @@ extern PROFILE_T s_profile; extern FILE *fdi; // file descriptor for input extern FILE *fdo; // file descriptor for output extern int tty_fd; // file descriptor for tty device -struct termios oldtio; // old tty setting +extern struct termios oldtio; // old tty setting