diff options
author | Xin LI <delphij@FreeBSD.org> | 2012-12-11 01:12:29 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2012-12-11 01:12:29 +0000 |
commit | aae7510122b4c7b0e3bd8f817afb6e4ca2e2c060 (patch) | |
tree | 897b0be482163f626fa3597080b4b19d9b008ff1 /sbin | |
parent | d3bfafb4f6f589a914db0148b572037af0ba2703 (diff) | |
download | src-aae7510122b4c7b0e3bd8f817afb6e4ca2e2c060.tar.gz src-aae7510122b4c7b0e3bd8f817afb6e4ca2e2c060.zip |
In parse():
- Only operate on copy, don't operate on source.
- Eliminate home-rolled strsep().
- Constify the parameter.
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=244104
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/sysctl/sysctl.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 7379155353c6..83e1337c65d2 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -62,7 +62,7 @@ static int aflag, bflag, dflag, eflag, hflag, iflag; static int Nflag, nflag, oflag, qflag, xflag, warncount; static int oidfmt(int *, int, char *, u_int *); -static void parse(char *); +static void parse(const char *); static int show_var(int *, int); static int sysctl_all(int *oid, int len); static int name2oid(char *, int *); @@ -161,7 +161,7 @@ main(int argc, char **argv) * Set a new value if requested. */ static void -parse(char *string) +parse(const char *string) { int len, i, j; void *newval = 0; @@ -176,12 +176,11 @@ parse(char *string) char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ]; u_int kind; - bufp = buf; + cp = buf; if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) errx(1, "oid too long: '%s'", string); - if ((cp = strchr(string, '=')) != NULL) { - *strchr(buf, '=') = '\0'; - *cp++ = '\0'; + bufp = strsep(&cp, "="); + if (cp != NULL) { while (isspace(*cp)) cp++; newval = cp; |