9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9f6fbda00aec1be7d746dc8d118d693eecd6cec5
parent 5d9e18766eda2ecd5a2faa5aac6b43be0da7a1e4
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date:   Thu, 24 Nov 2022 19:24:55 +0100

os9: Improve iconf()

Diffstat:
Msrc/os9/sys.c | 27++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/os9/sys.c b/src/os9/sys.c @@ -68,6 +68,15 @@ iconf(void) int n; Chan *c; char line[80], *s, *p; + static struct { + char *verb; + void (*fn)(char *); + } words[] = { + "write", writeline, + "bind", bindline, + "mount", mountline, + NULL + }, *bp; if ((c = chanopen("/blobs/conf", O_READ)) == NULL) { kprint("missed kernel namespace configuration\n"); @@ -87,17 +96,17 @@ iconf(void) while (isspace(*p)) *p++ = '\0'; - if (strcmp(s, "write") == 0) { - writeline(p); - } else if (strcmp(s, "bind") == 0) { - bindline(p); - } else if (strcmp(s, "mount") == 0) { - mountline(p); - } else { - kprint("iconf: incorrect verb '%s'\n", s); - continue; + for (bp = words; bp->verb; ++bp) { + if (strcmp(s, bp->verb) == 0) { + (*bp->fn)(p); + break; + } } + + if (!bp->verb) + kprint("iconf: incorrect verb '%s'\n", s); } + if (n < 0) kprint("iconf: error reading configuration:%r\n");