[Apcupsd-commits] apcupsd/src/drivers/dumb dumbsetup.c, 1.11, 1.11.2.1
Brought to you by:
adk0212
From: Adam K. <ad...@us...> - 2009-07-26 14:51:09
|
Update of /cvsroot/apcupsd/apcupsd/src/drivers/dumb In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12776/dumb Modified Files: Tag: Branch-3_14 dumbsetup.c Log Message: Automatically add \\.\ UNC prefix to COMx device name on Windows. This allows selection of ports above COM9. Index: dumbsetup.c =================================================================== RCS file: /cvsroot/apcupsd/apcupsd/src/drivers/dumb/dumbsetup.c,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -d -r1.11 -r1.11.2.1 --- dumbsetup.c 28 Jul 2006 23:06:35 -0000 1.11 +++ dumbsetup.c 26 Jul 2009 14:50:59 -0000 1.11.2.1 @@ -49,8 +49,20 @@ "apcsmart_ups_open called twice. This shouldn't happen."); } - if ((ups->fd = open(ups->device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) - Error_abort2(_("Cannot open UPS port %s: %s\n"), ups->device, strerror(errno)); + char *opendev = ups->device; + +#ifdef HAVE_MINGW + // On Win32 add \\.\ UNC prefix to COMx in order to correctly address + // ports >= COM10. + char device[MAXSTRING]; + if (!strnicmp(ups->device, "COM", 3)) { + snprintf(device, sizeof(device), "\\\\.\\%s", ups->device); + opendev = device; + } +#endif + + if ((ups->fd = open(opendev, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) + Error_abort2(_("Cannot open UPS port %s: %s\n"), opendev, strerror(errno)); /* Cancel the no delay we just set */ cmd = fcntl(ups->fd, F_GETFL, 0); |