* [PATCH] whereis: move token assignment into loop syntax
@ 2012-01-29 14:25 Davidlohr Bueso
2012-01-30 9:08 ` Voelker, Bernhard
0 siblings, 1 reply; 3+ messages in thread
From: Davidlohr Bueso @ 2012-01-29 14:25 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
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 <dave@gnu.org>
---
misc-utils/whereis.c | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 925cc93..eee4bf6 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -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;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] whereis: move token assignment into loop syntax
2012-01-29 14:25 [PATCH] whereis: move token assignment into loop syntax Davidlohr Bueso
@ 2012-01-30 9:08 ` Voelker, Bernhard
2012-01-30 12:24 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Voelker, Bernhard @ 2012-01-30 9:08 UTC (permalink / raw)
To: dave@gnu.org, Karel Zak; +Cc: util-linux
Davidlohr Bueso wrote:
> ... use for() naturally instead.
> - 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] whereis: move token assignment into loop syntax
2012-01-30 9:08 ` Voelker, Bernhard
@ 2012-01-30 12:24 ` Karel Zak
0 siblings, 0 replies; 3+ messages in thread
From: Karel Zak @ 2012-01-30 12:24 UTC (permalink / raw)
To: Voelker, Bernhard; +Cc: dave@gnu.org, util-linux
On Mon, Jan 30, 2012 at 10:08:41AM +0100, Voelker, Bernhard wrote:
> Davidlohr Bueso wrote:
>
> > ... use for() naturally instead.
>
> > - 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
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-30 12:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-29 14:25 [PATCH] whereis: move token assignment into loop syntax Davidlohr Bueso
2012-01-30 9:08 ` Voelker, Bernhard
2012-01-30 12:24 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox