From 874ca8c79de8f2ee3d4b08263f27a2f18235c087 Mon Sep 17 00:00:00 2001 From: Stephane Fillod Date: Sat, 23 Jun 2012 16:40:29 +0200 Subject: [PATCH] allow seamless access to ports higher than COM9 --- lib/termios.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/termios.c b/lib/termios.c index a97a8e496..6149b324c 100644 --- a/lib/termios.c +++ b/lib/termios.c @@ -1066,7 +1066,7 @@ static struct termios_list *add_port( const char *filename ) */ port->MSR = 0; - strcpy(port->filename, filename ); + strncpy(port->filename, filename, sizeof(port->filename)-1); /* didnt free well? strdup( filename ); */ if( ! port->filename ) goto fail; @@ -1182,14 +1182,24 @@ int win32_serial_open( const char *filename, int flags, ... ) { struct termios_list *index; char message[80]; + char fullfilename[80]; ENTER( "serial_open" ); - if ( port_opened( filename ) ) + + fullfilename[sizeof(fullfilename)-1] = '\0'; + /* according to http://support.microsoft.com/kb/115831 + * this is necessary for COM ports larger than COM9 */ + if (memcmp(filename, "\\\\.\\", 4) != 0) + snprintf(fullfilename, sizeof(fullfilename)-1, "\\\\.\\%s", filename); + else + strncpy(fullfilename, filename, sizeof(fullfilename)-1); + + if ( port_opened( fullfilename ) ) { report( "Port is already opened\n" ); return( -1 ); } - index = add_port( filename ); + index = add_port( fullfilename ); if( !index ) { report( "serial_open !index\n" ); @@ -1201,7 +1211,7 @@ int win32_serial_open( const char *filename, int flags, ... ) if ( open_port( index ) ) { sprintf( message, "serial_open(): Invalid Port Reference for %s\n", - filename ); + fullfilename ); report( message ); win32_serial_close( index->fd ); return -1;