mirror of https://github.com/ericonr/sndio.git
Use _sndio_parsenum() to parse device numbers. From miko@.
This commit is contained in:
parent
471495bd21
commit
d4048a3a19
|
@ -449,27 +449,6 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
parsedev(const char *str, unsigned int *rval)
|
||||
{
|
||||
const char *p = str;
|
||||
unsigned int val;
|
||||
|
||||
for (val = 0; *p >= '0' && *p <= '9'; p++) {
|
||||
val = 10 * val + (*p - '0');
|
||||
if (val >= 16) {
|
||||
DPRINTF("%s: number too large\n", str);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (p == str) {
|
||||
DPRINTF("%s: number expected\n", str);
|
||||
return NULL;
|
||||
}
|
||||
*rval = val;
|
||||
return p;
|
||||
}
|
||||
|
||||
static const char *
|
||||
parsestr(const char *str, char *rstr, unsigned int max)
|
||||
{
|
||||
|
@ -516,7 +495,7 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode)
|
|||
} else
|
||||
*host = '\0';
|
||||
if (*p == ',') {
|
||||
p = parsedev(++p, &unit);
|
||||
p = _sndio_parsenum(++p, &unit, 15);
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
} else
|
||||
|
@ -525,7 +504,7 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode)
|
|||
DPRINTF("%s: '/' expected\n", str);
|
||||
return 0;
|
||||
}
|
||||
p = parsedev(++p, &devnum);
|
||||
p = _sndio_parsenum(++p, &devnum, 15);
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
if (*p == '.') {
|
||||
|
|
|
@ -68,13 +68,17 @@ _sndio_parsenum(const char *str, unsigned int *num, unsigned int max)
|
|||
dig = *p - '0';
|
||||
if (dig >= 10)
|
||||
break;
|
||||
if (val > maxq || (val == maxq && dig > maxr))
|
||||
if (val > maxq || (val == maxq && dig > maxr)) {
|
||||
DPRINTF("%s: number too large\n", str);
|
||||
return NULL;
|
||||
}
|
||||
val = val * 10 + dig;
|
||||
p++;
|
||||
}
|
||||
if (p == str)
|
||||
if (p == str) {
|
||||
DPRINTF("%s: number expected\n", str);
|
||||
return NULL;
|
||||
}
|
||||
*num = val;
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue