Skip to contentSkip to conversation

whereis: move token assignment into loop syntax

PATCH In review Davidlohr Bueso 3 participants 3 messages Jan 29, 2012 – Jan 30, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 whereis: move token assignment into loop syntax

From: Davidlohr Bueso <[email protected]>
Date: Sun, 29 Jan 2012 15:22:41 +0100

We can save a few lines and use for() naturally instead.

---
 misc-utils/whereis.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
misc-utils/whereis.c +1 -5
index 925cc93..eee4bf6 100644
@@ -268,11 +268,7 @@ static void fillpath(void)
 		return;
 	pathcp = xstrdup(path);
 
-	for (tmp = pathcp; ; tmp = NULL) {
-		tok = strtok_r(tmp, ":", &key);
-		if (!tok)
-			break;
-
+	for (tmp = pathcp; tok = strtok_r(tmp, ":", &key); tmp = NULL) {
 		/* make sure we don't repeat the search path */
 		if (inpath(tok))
 			continue;
Signature · 1 line
1.7.4.1
#1 lore raw

misc-utils/whereis.c static void fillpath(void) · line 274

Quoted 11 lines · Davidlohr Bueso

... use for() naturally instead.

misc-utils/whereis.c +1 -5
-	for (tmp = pathcp; ; tmp = NULL) {
-		tok = strtok_r(tmp, ":", &key);
-		if (!tok)
-			break;
-
+	for (tmp = pathcp; tok = strtok_r(tmp, ":", &key); tmp = NULL) {
 		/* make sure we don't repeat the search path */
 		if (inpath(tok))
 			continue;

hmm, a repetitive assignment like "tmp = NULL" as the increment expression of the for-loop doesn't read too natural for me either. ;-)

Have a nice day,
Berny

maintainer
#2 lore raw
Quoted 4 lines · Bernhard
Quoted 1 line · Davidlohr Bueso

... use for() naturally instead.

Quoted 13 lines

misc-utils/whereis.c static void fillpath(void) · line 274

Quoted 9 lines
misc-utils/whereis.c +1 -5
-	for (tmp = pathcp; ; tmp = NULL) {
-		tok = strtok_r(tmp, ":", &key);
-		if (!tok)
-			break;
-
+	for (tmp = pathcp; tok = strtok_r(tmp, ":", &key); tmp = NULL) {
 		/* make sure we don't repeat the search path */
 		if (inpath(tok))
 			continue;

hmm, a repetitive assignment like "tmp = NULL" as the increment expression of the for-loop doesn't read too natural for me either. ;-)

Yes,

    for (tok = strtok_r(pathcp, ":", &key); tok;
         tok = strtok_r(NULL, ":", &key)) {

is more readable solution, 'tmp' is unnecessary. Fixed.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com