-/* $OpenBSD: opt.c,v 1.5 2021/01/29 11:21:00 ratchov Exp $ */
+/* $OpenBSD: opt.c,v 1.6 2021/01/29 11:25:05 ratchov Exp $ */
/*
* Copyright (c) 2008-2011 Alexandre Ratchov <alex@caoua.org>
*
int pmin, int pmax, int rmin, int rmax,
int maxweight, int mmc, int dup, unsigned int mode)
{
- struct opt *o;
- unsigned int len;
+ struct opt *o, **po;
+ unsigned int len, num;
char c;
- if (opt_byname(d, name)) {
- dev_log(d);
- log_puts(".");
- log_puts(name);
- log_puts(": already defined\n");
- return NULL;
- }
for (len = 0; name[len] != '\0'; len++) {
if (len == OPT_NAMEMAX) {
log_puts(name);
return NULL;
}
}
+ num = 0;
+ for (po = &opt_list; *po != NULL; po = &(*po)->next)
+ num++;
+ if (num >= OPT_NMAX) {
+ log_puts(name);
+ log_puts(": too many opts\n");
+ return NULL;
+ }
+ if (opt_byname(d, name)) {
+ dev_log(d);
+ log_puts(".");
+ log_puts(name);
+ log_puts(": already defined\n");
+ return NULL;
+ }
o = xmalloc(sizeof(struct opt));
+ o->num = num;
o->dev = d;
if (mode & MODE_PLAY) {
o->pmin = pmin;
o->dup = dup;
o->mode = mode;
memcpy(o->name, name, len + 1);
- o->next = opt_list;
- opt_list = o;
+ o->next = *po;
+ *po = o;
if (log_level >= 2) {
dev_log(d);
log_puts(".");
-/* $OpenBSD: opt.h,v 1.3 2021/01/29 11:21:00 ratchov Exp $ */
+/* $OpenBSD: opt.h,v 1.4 2021/01/29 11:25:05 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
#ifndef OPT_H
#define OPT_H
+#define OPT_NMAX 16
+
struct dev;
struct opt {
struct opt *next;
struct dev *dev;
+ int num;
#define OPT_NAMEMAX 11
char name[OPT_NAMEMAX + 1];
int maxweight; /* max dynamic range for clients */