make devnum mandatory

This commit is contained in:
Alexandre Ratchov 2011-11-08 09:32:00 +01:00
parent d0bc800ea8
commit c8f20fb97f
2 changed files with 24 additions and 22 deletions

View File

@ -42,10 +42,8 @@ opt_new(char *name, struct dev *dev,
exit(1); exit(1);
} }
c = name[len]; c = name[len];
if (c < 'a' && c > 'z' && if ((c < 'a' || c > 'z') &&
c < 'A' && c > 'Z' && (c < 'A' || c > 'Z')) {
c < '0' && c > '9' &&
c != '_') {
fprintf(stderr, "%s: '%c' not allowed\n", name, c); fprintf(stderr, "%s: '%c' not allowed\n", name, c);
exit(1); exit(1);
} }

View File

@ -411,10 +411,6 @@ parsedev(const char *str, unsigned *rval)
const char *p = str; const char *p = str;
unsigned val; unsigned val;
if (*p < '0' || *p > '9') {
DPRINTF("%s: number expected\n", str);
return NULL;
}
for (val = 0; *p >= '0' && *p <= '9'; p++) { for (val = 0; *p >= '0' && *p <= '9'; p++) {
val = 10 * val + (*p - '0'); val = 10 * val + (*p - '0');
if (val >= 16) { if (val >= 16) {
@ -422,6 +418,10 @@ parsedev(const char *str, unsigned *rval)
return NULL; return NULL;
} }
} }
if (p == str) {
DPRINTF("%s: number expected\n", str);
return NULL;
}
*rval = val; *rval = val;
return p; return p;
} }
@ -431,13 +431,17 @@ parsestr(const char *str, char *rstr, unsigned max)
{ {
const char *p = str; const char *p = str;
while (*p != '\0' && *p != ',') { while (*p != '\0' && *p != ',' && *p != '/') {
if (--max == 0) { if (--max == 0) {
DPRINTF("%s: too long\n", str); DPRINTF("%s: string too long\n", str);
return 0; return NULL;
} }
*rstr++ = *p++; *rstr++ = *p++;
} }
if (str == p) {
DPRINTF("%s: string expected\n", str);
return NULL;
}
*rstr = '\0'; *rstr = '\0';
return p; return p;
} }
@ -448,30 +452,28 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, unsigned type)
extern char *__progname; extern char *__progname;
int eof; int eof;
char host[NI_MAXHOST], opt[AMSG_OPTMAX]; char host[NI_MAXHOST], opt[AMSG_OPTMAX];
const char *p; const char *p = str;
unsigned unit, devnum; unsigned unit, devnum;
p = str;
if (*p == '@') { if (*p == '@') {
p = parsestr(++p, host, NI_MAXHOST); p = parsestr(++p, host, NI_MAXHOST);
if (p == NULL) if (p == NULL)
return 0; return 0;
} else } else
host[0] = '\0'; *host = '\0';
if (*p == ',') { if (*p == ',') {
p = parsedev(++p, &unit); p = parsedev(++p, &unit);
if (p == NULL) if (p == NULL)
return 0; return 0;
} else } else
unit = 0; unit = 0;
if (*p == '/' || *p == ':') { if (*p != '/' && *p != ':') {
p = parsedev(++p, &devnum); DPRINTF("%s: '/' expected\n", str);
if (p == NULL) return 0;
return 0; }
} else p = parsedev(++p, &devnum);
devnum = 0; if (p == NULL)
if (type) return 0;
devnum += 16; /* XXX */
if (*p == '.') { if (*p == '.') {
p = parsestr(++p, opt, AMSG_OPTMAX); p = parsestr(++p, opt, AMSG_OPTMAX);
if (p == NULL) if (p == NULL)
@ -482,6 +484,8 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, unsigned type)
DPRINTF("%s: junk at end of dev name\n", p); DPRINTF("%s: junk at end of dev name\n", p);
return 0; return 0;
} }
if (type)
devnum += 16; /* XXX */
DPRINTF("aucat_open: host=%s unit=%u devnum=%u opt=%s\n", DPRINTF("aucat_open: host=%s unit=%u devnum=%u opt=%s\n",
host, unit, devnum, opt); host, unit, devnum, opt);
if (host[0] != '\0') { if (host[0] != '\0') {