Allow digits in control names

This commit is contained in:
Alexandre Ratchov 2020-02-05 17:28:15 +01:00
parent 1bfe9a4f39
commit 92cc5b7bba
1 changed files with 14 additions and 6 deletions

View File

@ -22,10 +22,6 @@
#include <unistd.h>
#include <sndio.h>
#define IS_IDENT(c) (((c) >= 'a' && (c) <= 'z') || \
((c) >= 'A' && (c) <= 'Z') || \
((c) == '_'))
struct info {
struct info *next;
struct sioctl_desc desc;
@ -69,6 +65,18 @@ struct sioctl_hdl *hdl;
struct info *infolist;
int i_flag = 0, v_flag = 0, m_flag = 0;
static inline int
isname_first(int c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
static inline int
isname_next(int c)
{
return isname_first(c) || (c >= '0' && c <= '9') || (c == '_');
}
/*
* compare two sioctl_desc structures, used to sort infolist
*/
@ -410,11 +418,11 @@ parse_name(char **line, char *name)
char *p = *line;
unsigned len = 0;
if (!IS_IDENT(*p)) {
if (!isname_first(*p)) {
fprintf(stderr, "letter expected near '%s'\n", p);
return 0;
}
while (IS_IDENT(*p)) {
while (isname_next(*p)) {
if (len >= SIOCTL_NAMEMAX - 1) {
name[SIOCTL_NAMEMAX - 1] = '\0';
fprintf(stderr, "%s...: too long\n", name);