Add sp_get_port_by_name() function.

This commit is contained in:
Martin Ling 2013-11-03 21:35:46 +00:00 committed by Uwe Hermann
parent 5919c9134a
commit d4babed247
2 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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);