diff toys/which.c @ 295:5a0faa267866

Fix which (the meaning of -a was reversed, and it was finding the _last_ hit).
author Rob Landley <rob@landley.net>
date Sat, 17 May 2008 17:52:51 -0500
parents 163498bf547b
children d51be130fda2
line wrap: on
line diff
--- a/toys/which.c	Sat May 17 17:13:26 2008 -0500
+++ b/toys/which.c	Sat May 17 17:52:51 2008 -0500
@@ -6,7 +6,7 @@
  *
  * Not in SUSv3.
 
-USE_WHICH(NEWTOY(which, "a", TOYFLAG_USR|TOYFLAG_BIN))
+USE_WHICH(NEWTOY(which, "<1a", TOYFLAG_USR|TOYFLAG_BIN))
 
 config WHICH
 	bool "which"
@@ -20,8 +20,6 @@
 */
 #include "toys.h"
 
-#define OPT_a   1
-
 // Find an exectuable file either at a path with a slash in it (absolute or
 // relative to current directory), or in $PATH.  Returns absolute path to file,
 // or NULL if not found.
@@ -54,7 +52,7 @@
 		if (!access(list->str, X_OK)) {
 			puts(list->str);
 			// If we should stop at one match, do so
-			if (toys.optflags & OPT_a) {
+			if (!toys.optflags) {
 				llist_free(list, NULL);
 				break;
 			}
@@ -67,10 +65,7 @@
 
 void which_main(void)
 {
-	if (!*toys.optargs) toys.exitval++;
-	else {
-		int i;
-		for (i=0; toys.optargs[i]; i++)
-			toys.exitval |= which_in_path(toys.optargs[i]);
-	}
+	int i;
+	for (i=0; toys.optargs[i]; i++)
+		toys.exitval |= which_in_path(toys.optargs[i]);
 }