From 934dbf050b7f8043eab8f0f04365f18a6b9055f3 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 28 Feb 2007 21:30:06 +0000 Subject: [PATCH] Prepend \\.\ to configured serial line string, to allow easy access to ports above COM9. git-svn-id: svn://svn.tartarus.org/sgt/putty@7345 cda61777-01e9-0310-a592-d414129be87e --- doc/config.but | 4 +--- windows/winser.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/config.but b/doc/config.but index 29259572..3b744356 100644 --- a/doc/config.but +++ b/doc/config.but @@ -2976,9 +2976,7 @@ serial line you want PuTTY to talk to, if your computer has more than one serial port. On Windows, the first serial line is called \i\cw{COM1}, and if there -is a second it is called \cw{COM2}, and so on. A serial line with -a name other than \cw{COM1} to \cw{COM9} can be specified by prefixing -its name with \cw{\\\\.\\} - for instance, \cw{\\\\.\\COM10}. +is a second it is called \cw{COM2}, and so on. This configuration setting is also visible on the Session panel, where it replaces the \q{Host Name} box (see \k{config-hostname}) if diff --git a/windows/winser.c b/windows/winser.c index cd31b5af..9e6415e3 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -221,8 +221,39 @@ static const char *serial_init(void *frontend_handle, void **backend_handle, logevent(serial->frontend, msg); } - serport = CreateFile(cfg->serline, GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + { + /* + * Munge the string supplied by the user into a Windows filename. + * + * Windows supports opening a few "legacy" devices (including + * COM1-9) by specifying their names verbatim as a filename to + * open. (Thus, no files can ever have these names. See + * + * ("Naming a File") for the complete list of reserved names.) + * + * However, this doesn't let you get at devices COM10 and above. + * For that, you need to specify a filename like "\\.\COM10". + * This is also necessary for special serial and serial-like + * devices such as \\.\WCEUSBSH001. It also works for the "legacy" + * names, so you can do \\.\COM1 (verified as far back as Win95). + * See + * (CreateFile() docs). + * + * So, we believe that prepending "\\.\" should always be the + * Right Thing. However, just in case someone finds something to + * talk to that doesn't exist under there, if the serial line + * contains a backslash, we use it verbatim. (This also lets + * existing configurations using \\.\ continue working.) + */ + char *serfilename = + dupprintf("%s%s", + strchr(cfg->serline, '\\') ? "" : "\\\\.\\", + cfg->serline); + serport = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + sfree(serfilename); + } + if (serport == INVALID_HANDLE_VALUE) return "Unable to open serial port"; -- 2.11.0