From 68fc1596542b13980a4ce4f1154683189cd2b463 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 10 Sep 2022 18:59:27 +0200 Subject: [PATCH] Fix listing of serial devices in MSYS2/Cygwin We generally try to list serial devices by ID but in the MSYS2/Cygwin environment serial devices are not available by ID and so we simply list the basic serial device paths instead. --- src/tty.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tty.c b/src/tty.c index 8064ac1..4cbee06 100644 --- a/src/tty.c +++ b/src/tty.c @@ -54,8 +54,13 @@ #ifdef __APPLE__ #define PATH_SERIAL_DEVICES "/dev/" +#define PREFIX_TTY_DEVICES "tty." +#elifdef __CYGWIN__ +#define PATH_SERIAL_DEVICES "/dev/serial/by-id/" +#define PREFIX_TTY_DEVICES "ttyS" #else #define PATH_SERIAL_DEVICES "/dev/serial/by-id/" +#define PREFIX_TTY_DEVICES "" #endif #ifndef CMSPAR @@ -1343,11 +1348,10 @@ void list_serial_devices(void) { if ((strcmp(dir->d_name, ".")) && (strcmp(dir->d_name, ".."))) { -#ifdef __APPLE__ -#define TTY_DEVICES_PREFIX "tty." - if (!strncmp(dir->d_name, TTY_DEVICES_PREFIX, sizeof(TTY_DEVICES_PREFIX) - 1)) -#endif - printf("%s%s\n", PATH_SERIAL_DEVICES, dir->d_name); + if (!strncmp(dir->d_name, PREFIX_TTY_DEVICES, sizeof(PREFIX_TTY_DEVICES) - 1)) + { + printf("%s%s\n", PATH_SERIAL_DEVICES, dir->d_name); + } } } closedir(d);