From 92cc5b7bbad17ce650f72a89daf9955501972e7a Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Wed, 5 Feb 2020 17:28:15 +0100 Subject: [PATCH] Allow digits in control names --- sndioctl/sndioctl.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sndioctl/sndioctl.c b/sndioctl/sndioctl.c index abadb71..75b1934 100644 --- a/sndioctl/sndioctl.c +++ b/sndioctl/sndioctl.c @@ -22,10 +22,6 @@ #include #include -#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);