svn commit: r279806 - head/usr.sbin/autofs

Edward Tomasz Napierala trasz at FreeBSD.org
Mon Mar 9 12:00:00 UTC 2015


Author: trasz
Date: Mon Mar  9 11:59:58 2015
New Revision: 279806
URL: https://svnweb.freebsd.org/changeset/base/279806

Log:
  Minor optimization/cleanup in node_path(); no functional changes.
  
  MFC after:	1 month
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/usr.sbin/autofs/common.c

Modified: head/usr.sbin/autofs/common.c
==============================================================================
--- head/usr.sbin/autofs/common.c	Mon Mar  9 10:29:15 2015	(r279805)
+++ head/usr.sbin/autofs/common.c	Mon Mar  9 11:59:58 2015	(r279806)
@@ -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 *


More information about the svn-src-all mailing list