diff options
| author | 2017-07-09 18:45:27 +0000 | |
|---|---|---|
| committer | 2017-07-09 18:45:27 +0000 | |
| commit | cbfbc5190786639e07f1e30de9b06f6a7c9818f3 (patch) | |
| tree | b8585a1d28dfcc83c1212e30314e04f763082636 /sbin/dhclient/parse.c | |
| parent | document PROGS, okay jmc@ (diff) | |
| download | wireguard-openbsd-cbfbc5190786639e07f1e30de9b06f6a7c9818f3.tar.xz wireguard-openbsd-cbfbc5190786639e07f1e30de9b06f6a7c9818f3.zip | |
Some parsing code cleanup: add parse_boolean(); pass literal format
chars to parse_decimal() instead of less obvious *fmt; refactor
to eliminate need for the 'alloc:' and 'bad_flag:' labels and the
invidious backwards goto's to them.
Diffstat (limited to 'sbin/dhclient/parse.c')
| -rw-r--r-- | sbin/dhclient/parse.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index a88469a0942..841841d9093 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.55 2017/07/08 00:36:10 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.56 2017/07/09 18:45:27 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -246,6 +246,29 @@ parse_lease_time(FILE *cfile, time_t *timep) } int +parse_boolean(FILE *cfile, unsigned char *buf) +{ + char *val; + int token; + + token = next_token(&val, cfile); + if (is_identifier(token)) { + if (strcasecmp(val, "true") == 0 || + strcasecmp(val, "on") == 0) { + buf[0] = 1; + return (1); + } + if (strcasecmp(val, "false") == 0 || + strcasecmp(val, "off") == 0) { + buf[0] = 0; + return (1); + } + } + + return (0); +} + +int parse_decimal(FILE *cfile, unsigned char *buf, char fmt) { char *val; |
