1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Make sure OS handles are set correctly for unopened / closed ports.

This commit is contained in:
Martin Ling 2013-11-18 20:00:15 +00:00
parent c6754b4517
commit 8f471c669f

View File

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