]> datadissipation.net git - ust.git/commitdiff
TERMIOS_STRUCT macro fix
authorgit <redacted>
Sat, 21 Feb 2026 10:14:45 +0000 (05:14 -0500)
committergit <redacted>
Sat, 21 Feb 2026 10:14:45 +0000 (05:14 -0500)
ust.c

diff --git a/ust.c b/ust.c
index 2aa9a240a208c6a152468b10a668070cc6389af7..8ad6dd1aa6b8bda4d157b3d34c16dd146c698064 100644 (file)
--- a/ust.c
+++ b/ust.c
@@ -50,7 +50,7 @@ typedef struct {
        ssize_t sizesm;
 } Sizes;
 
-typedef struct{
+typedef struct {
        int crinlf;
        int crtolf;
        int lfincr;
@@ -70,7 +70,7 @@ static unsigned int strtoui(const char *str, const char *msg, unsigned int min);
 static int troptions(CRLFOpt *options, const char *str);
 static int setroptions();
 static inline unsigned int lsbmask(unsigned int n);
-static inline int termchck(const void *term);
+static inline int termchck(const struct TERMIOS_STRUCT *term);
 static void interchck();
 static void cechck();
 static void *writeport(void *unused);
@@ -82,15 +82,18 @@ static inline ssize_t rmchar(char *buff, ssize_t sread, int *scratch, const Args
 static void sighandl(int signo);
 static void die(int code, const char *msg, ...);
 
-static struct TERMIOS_STRUCT cntrl, origterm = { 0 }, newterm = { 0 };
+static struct TERMIOS_STRUCT cntrl, /* device struct */
+                             origterm = { 0 }, /* controlling terminal structs */
+                             newterm = { 0 };
 
 static Args bsargs = {DEL, DEL, 0};
 static const Args nocrargs = {CR, 0, 0},
                   nolfargs = {LF, '\0', 0}, /* null-terminator is for use inside `getcmd()` */
                   lfincrargs = {CR, LF, 1},
-                  crinlfargs = {LF, CR, -1};
+                  crinlfargs = {LF, CR, 0};
+
 static struct timespec wts;
-static const unsigned int uintmax = ~(unsigned int)0; /* unsigned -1 to return on error */
+static const unsigned int uintmax = ~(unsigned int)0; /* unsigned -1 used to return an error */
 static int interactive = 0;
 static char *writebuff = NULL;
 static char *readbuff = NULL;
@@ -174,6 +177,7 @@ openport()
                        die(1, "failed to lock the device, exiting now\n");
                }
        }
+
        /*
         * Baud
         */
@@ -190,7 +194,8 @@ openport()
        cntrl.c_iflag &= ~(ISTRIP | BRKINT);
        cntrl.c_cflag &= ~(PARENB | PARODD);
 
-       if (verbose) fprintf(stderr, "setting parity [even: %d, odd: %d]\n", parity & 1, (parity & 2) >> 1);
+       if (verbose) fprintf(stderr, "setting parity [even: %d, odd: %d]\n",\
+                       parity & 1, (parity & 2) >> 1);
 
        if (parity == 1)
                cntrl.c_cflag |= PARENB;
@@ -198,8 +203,8 @@ openport()
                cntrl.c_cflag |= PARENB | PARODD;
 
        if (settermattr(fd, &cntrl) == -1)
-               die(2, "failed to set parity [even: %d, odd: %d]\n", parity & 1, (parity & 2) >> 1);
-
+               die(2, "failed to set parity [even: %d, odd: %d]\n",\
+                               parity & 1, (parity & 2) >> 1);
 
        /*
         * Flow control
@@ -370,7 +375,7 @@ lsbmask(unsigned int n)
 }
 
 inline int
-termchck(const void *term)
+termchck(const struct TERMIOS_STRUCT *term)
 {
        for (size_t i = 0; i < sizeof(struct TERMIOS_STRUCT); i++)
                if (((char*)term)[i] != 0)
@@ -442,7 +447,7 @@ writeport(void *unused)
        }
        /* ust kills itself upon receiving a signal so no fancy `nanosleep()` features needed */
        nanosleep(&timeout, NULL);
-       die(0, "\n[EOF]\n");
+       die(0, "[EOF]\n");
        return NULL;
 }
 
@@ -485,8 +490,6 @@ readport(void *unused)
                }
                nanosleep(&ts, NULL);
        }
-       if (isatty(STDIN_FILENO)) 
-               settermattr(STDIN_FILENO, &origterm);
        return NULL;
 }