From: Martin Ling Date: Sun, 3 Nov 2013 21:35:46 +0000 (+0000) Subject: Add sp_get_port_by_name() function. X-Git-Tag: libserialport-0.1.0~149 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=d4babed247a917219709f5bb50241d54e1a037be;hp=5919c9134abff82adeed3941fde27fed65d01dcb;p=libserialport.git Add sp_get_port_by_name() function. --- diff --git a/serialport.c b/serialport.c index 3c81f9e..9330376 100644 --- a/serialport.c +++ b/serialport.c @@ -45,11 +45,14 @@ #include "serialport.h" -static struct sp_port *sp_port_new(const char *portname) +struct sp_port *sp_get_port_by_name(const char *portname) { struct sp_port *port; int len; + if (!portname) + return NULL; + if (!(port = malloc(sizeof(struct sp_port)))) return NULL; @@ -74,7 +77,7 @@ static struct sp_port **sp_list_append(struct sp_port **list, const char *portna if (!(tmp = realloc(list, sizeof(struct sp_port *) * (count + 2)))) goto fail; list = tmp; - if (!(list[count] = sp_port_new(portname))) + if (!(list[count] = sp_get_port_by_name(portname))) goto fail; list[count + 1] = NULL; return list; diff --git a/serialport.h b/serialport.h index 8c42720..9a32109 100644 --- a/serialport.h +++ b/serialport.h @@ -79,6 +79,7 @@ enum { SP_FLOW_SOFTWARE = 2 }; +struct sp_port *sp_get_port_by_name(const char *portname); struct sp_port **sp_list_ports(void); void sp_free_port_list(struct sp_port **ports); int sp_open(struct sp_port *port, int flags);