mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Add sp_get_port_by_name() function.
This commit is contained in:
parent
5919c9134a
commit
d4babed247
@ -45,11 +45,14 @@
|
|||||||
|
|
||||||
#include "serialport.h"
|
#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;
|
struct sp_port *port;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
if (!portname)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!(port = malloc(sizeof(struct sp_port))))
|
if (!(port = malloc(sizeof(struct sp_port))))
|
||||||
return NULL;
|
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))))
|
if (!(tmp = realloc(list, sizeof(struct sp_port *) * (count + 2))))
|
||||||
goto fail;
|
goto fail;
|
||||||
list = tmp;
|
list = tmp;
|
||||||
if (!(list[count] = sp_port_new(portname)))
|
if (!(list[count] = sp_get_port_by_name(portname)))
|
||||||
goto fail;
|
goto fail;
|
||||||
list[count + 1] = NULL;
|
list[count + 1] = NULL;
|
||||||
return list;
|
return list;
|
||||||
|
@ -79,6 +79,7 @@ enum {
|
|||||||
SP_FLOW_SOFTWARE = 2
|
SP_FLOW_SOFTWARE = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sp_port *sp_get_port_by_name(const char *portname);
|
||||||
struct sp_port **sp_list_ports(void);
|
struct sp_port **sp_list_ports(void);
|
||||||
void sp_free_port_list(struct sp_port **ports);
|
void sp_free_port_list(struct sp_port **ports);
|
||||||
int sp_open(struct sp_port *port, int flags);
|
int sp_open(struct sp_port *port, int flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user