Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 May 2015 13:18:03 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r283227 - stable/10/usr.sbin/autofs
Message-ID:  <201505211318.t4LDI3GH093449@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Thu May 21 13:18:02 2015
New Revision: 283227
URL: https://svnweb.freebsd.org/changeset/base/283227

Log:
  MFC r279806:
  
  Minor optimization/cleanup in node_path(); no functional changes.

Modified:
  stable/10/usr.sbin/autofs/common.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/autofs/common.c
==============================================================================
--- stable/10/usr.sbin/autofs/common.c	Thu May 21 13:13:56 2015	(r283226)
+++ stable/10/usr.sbin/autofs/common.c	Thu May 21 13:18:02 2015	(r283227)
@@ -561,7 +561,6 @@ static char *
 node_path_x(const struct node *n, char *x)
 {
 	char *path;
-	size_t len;
 
 	if (n->n_parent == NULL)
 		return (x);
@@ -580,14 +579,6 @@ node_path_x(const struct node *n, char *
 	path = separated_concat(n->n_key, x, '/');
 	free(x);
 
-	/*
-	 * Strip trailing slash.
-	 */
-	len = strlen(path);
-	assert(len > 0);
-	if (path[len - 1] == '/')
-		path[len - 1] = '\0';
-
 	return (node_path_x(n->n_parent, path));
 }
 
@@ -598,8 +589,19 @@ node_path_x(const struct node *n, char *
 char *
 node_path(const struct node *n)
 {
+	char *path;
+	size_t len;
+
+	path = node_path_x(n, checked_strdup(""));
+
+	/*
+	 * Strip trailing slash, unless the whole path is "/".
+	 */
+	len = strlen(path);
+	if (len > 1 && path[len - 1] == '/')
+		path[len - 1] = '\0';
 
-	return (node_path_x(n, checked_strdup("")));
+	return (path);
 }
 
 static char *



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