Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Dec 2012 00:25:22 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r244670 - stable/8/sbin/sysctl
Message-ID:  <201212250025.qBP0PMYf019671@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Tue Dec 25 00:25:22 2012
New Revision: 244670
URL: http://svnweb.freebsd.org/changeset/base/244670

Log:
  MFC r244104:
  
  In parse():
  
   - Only operate on copy, don't operate on source.
   - Eliminate home-rolled strsep().
   - Constify the parameter.

Modified:
  stable/8/sbin/sysctl/sysctl.c
Directory Properties:
  stable/8/sbin/sysctl/   (props changed)

Modified: stable/8/sbin/sysctl/sysctl.c
==============================================================================
--- stable/8/sbin/sysctl/sysctl.c	Tue Dec 25 00:24:43 2012	(r244669)
+++ stable/8/sbin/sysctl/sysctl.c	Tue Dec 25 00:25:22 2012	(r244670)
@@ -62,7 +62,7 @@ static int	aflag, bflag, dflag, eflag, h
 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 *);
@@ -162,7 +162,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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212250025.qBP0PMYf019671>