--- /dev/null
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
/* lock the opened device */
const int exclusive = 1; /*(0|1)*/
+/*
+ * set the device to blocking mode,
+ * on some systems this will stop all threads
+ * of a process during read/write, thus rendering
+ * ust unusable
+ */
+const int blocking = 1; /*(0|1)*/
+
/* escape character for interactive use */
const char escapechar = '~';
/* exit timeout after piped ust reaches EOF */
long stimeout = 0;
-long nstimeout = 1000;
+long nstimeout = 10000;
/*
* device name
+/* see LICENSE for license details */
#include <sys/ioctl.h>
#include <errno.h>
#define IXONXOFF (IXON | IXOFF)
+#if defined(CCDTR_IFLOW) && defined(CDSR_OFLOW)
+ #define CDTRDSR (CDTR_IFLOW | CDSR_OFLOW)
+#endif
+
#ifdef __linux__
#define TERMIOS_STRUCT termios2
#else
#define TERMIOS_STRUCT termios
#endif
-#if defined(CCDTR_IFLOW) && defined(CDSR_OFLOW)
- #define CDTRDSR (CDTR_IFLOW | CDSR_OFLOW)
-#endif
-
typedef struct {
char find;
char input;
if (!isatty(fd))
die(2, "device \"%s\" is not a TTY\n", line);
- flags = fcntl(fd, F_GETFL, 0);
- /* opened to check with non-blocking mode, now set to blocking */
- flags &= ~(O_NONBLOCK | O_NDELAY);
+ if (blocking) {
+ flags = fcntl(fd, F_GETFL, 0);
+ /* opened to check with non-blocking mode, now set to blocking */
+ flags &= ~(O_NONBLOCK | O_NDELAY);
- if (fcntl(fd, F_SETFL, flags) == -1) {
- perror("fcntl");
- die(1, "exiting now\n");
+ if (fcntl(fd, F_SETFL, flags) == -1) {
+ perror("fcntl");
+ die(1, "exiting now\n");
+ }
}
-
+
if (gettermattr(fd, &cntrl) == -1)
die(1, "failed to get device attributes\n");
/* ust kills itself upon receiving a signal so no fancy `nanosleep()` features needed */
nanosleep(&timeout, NULL);
die(0, "[EOF]\n");
+
+ /* unreachable */
return NULL;
}
}
nanosleep(&ts, NULL);
}
+
+ /* unreachable */
return NULL;
}
}
if (!c)
return(size);
- if (size == 1 && c == 1 && scratch[0] == 0) {
+ if (size == 1 && c == 1) {
buff[to ^ 1] = args->input;
buff[to] = args->find;
return 2;
}
if (!c)
return(size);
- if (size == 1 && c == 1 && scratch[0] == 0)
+ if (size == 1 && c == 1)
return 0;
for (int i = c; i >= 0; i--) {
pthread_create(&readthread, NULL, readport, NULL);
pthread_join(writethread, NULL);
pthread_join(readthread, NULL);
+
+ /* unreachable */
+ return 0;
}