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.
This commit is contained in:
Martin Lund 2022-09-10 18:59:27 +02:00
parent 3c8d7fa786
commit 68fc159654

View file

@ -54,8 +54,13 @@
#ifdef __APPLE__ #ifdef __APPLE__
#define PATH_SERIAL_DEVICES "/dev/" #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 #else
#define PATH_SERIAL_DEVICES "/dev/serial/by-id/" #define PATH_SERIAL_DEVICES "/dev/serial/by-id/"
#define PREFIX_TTY_DEVICES ""
#endif #endif
#ifndef CMSPAR #ifndef CMSPAR
@ -1343,11 +1348,10 @@ void list_serial_devices(void)
{ {
if ((strcmp(dir->d_name, ".")) && (strcmp(dir->d_name, ".."))) if ((strcmp(dir->d_name, ".")) && (strcmp(dir->d_name, "..")))
{ {
#ifdef __APPLE__ if (!strncmp(dir->d_name, PREFIX_TTY_DEVICES, sizeof(PREFIX_TTY_DEVICES) - 1))
#define TTY_DEVICES_PREFIX "tty." {
if (!strncmp(dir->d_name, TTY_DEVICES_PREFIX, sizeof(TTY_DEVICES_PREFIX) - 1)) printf("%s%s\n", PATH_SERIAL_DEVICES, dir->d_name);
#endif }
printf("%s%s\n", PATH_SERIAL_DEVICES, dir->d_name);
} }
} }
closedir(d); closedir(d);