whereis: move token assignment into loop syntax
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.
Signed-off-by Davidlohr Bueso <[email protected]>
--- misc-utils/whereis.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
misc-utils/whereis.c +1 -5
@@ -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
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
Karel Zak
maintainerQuoted 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