]> sigrok.org Git - libserialport.git/commitdiff
Make sure OS handles are set correctly for unopened / closed ports.
authorMartin Ling <redacted>
Mon, 18 Nov 2013 20:00:15 +0000 (20:00 +0000)
committerMartin Ling <redacted>
Mon, 18 Nov 2013 20:00:15 +0000 (20:00 +0000)
serialport.c

index f95afd0cd0af8d537e6576433654ad0107ac3b87..7f452db3dbefd5325a8562ab64fb4bc5cc903e9e 100644 (file)
@@ -121,6 +121,12 @@ int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)
 
        memcpy(port->name, portname, len);
 
+#ifdef _WIN32
+       port->hdl = INVALID_HANDLE_VALUE;
+#else
+       port->fd = -1;
+#endif
+
        *port_ptr = port;
 
        return SP_OK;
@@ -491,10 +497,12 @@ int sp_close(struct sp_port *port)
        /* Returns non-zero upon success, 0 upon failure. */
        if (CloseHandle(port->hdl) == 0)
                return SP_ERR_FAIL;
+       port->hdl = INVALID_HANDLE_VALUE;
 #else
        /* Returns 0 upon success, -1 upon failure. */
        if (close(port->fd) == -1)
                return SP_ERR_FAIL;
+       port->fd = -1;
 #endif
 
        return SP_OK;