diff --git a/src/tty.c b/src/tty.c index f2d123e..96b62ad 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1332,7 +1332,13 @@ static bool is_serial_device(const char *format, ...) return false; } - if (stat(filename, &st) != 0) + fd = open(filename, O_RDONLY | O_NONBLOCK | O_NOCTTY); + if (fd == -1) + { + return false; + } + + if (fstat(fd, &st) == -1) { return false; } @@ -1343,12 +1349,6 @@ static bool is_serial_device(const char *format, ...) return false; } - fd = open(filename, O_RDONLY | O_NONBLOCK | O_NOCTTY); - if (fd == -1) - { - return false; - } - // Make sure it is a tty status = isatty(fd); if (status == 0)