From: Martin Ling Date: Mon, 18 Nov 2013 20:00:15 +0000 (+0000) Subject: Make sure OS handles are set correctly for unopened / closed ports. X-Git-Tag: libserialport-0.1.0~109 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8f471c669fb183ceaed529a773e71a67cc7fe4b7;p=libserialport.git Make sure OS handles are set correctly for unopened / closed ports. --- diff --git a/serialport.c b/serialport.c index f95afd0..7f452db 100644 --- a/serialport.c +++ b/serialport.c @@ -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;