[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [BusyBox] bug#1066: another smaller patch
From:       "David Douthitt" <ssrat () mailbag ! com>
Date:       2000-10-23 18:34:36
[Download RAW message or body]

On 23 Oct 2000, at 11:51, Matt Kraai wrote:

> How about the following, which is similar to the original only with
> one less variable and using EXIT_* instead of TRUE/FALSE? 

> Index: which.c
> ===================================================================
> RCS file: /var/cvs/busybox/which.c,v
> retrieving revision 1.10
> diff -u -r1.10 which.c
> --- which.c	2000/09/25 21:45:58	1.10
> +++ which.c	2000/10/23 17:42:50
> @@ -28,7 +28,7 @@
>  {
>  	char *path_list, *path_n;
>  	struct stat filestat;
> -	int i, count=1;
> +	int i, count=1, status = EXIT_SUCCESS;
>  
>  	if (argc <= 1 || **(argv + 1) == '-')
>  		usage(which_usage);
> @@ -61,8 +61,10 @@
>  			}
>  			path_n += (strlen(path_n) + 1);
>  		}
> +		if (i == count)
> +			status = EXIT_FAILURE;
>  	}
> -	return(TRUE);
> +	return status;
>  }
>  
>  /*

I wouldn't think it would be a good idea to use a loop variable 
outside of a loop, or to rely on its value.  I went back and tried to 
tighten my quick hack, and I couldn't find much.  This is the patch:

--- which.c.orig        Mon Oct 23 11:12:15 2000
+++ which.c     Mon Oct 23 13:33:32 2000
@@ -28,7 +28,7 @@
 {
        char *path_list, *path_n;
        struct stat filestat;
-       int i, count=1;
+       int i, found, count=1, status=EXIT_SUCCESS;

        if (argc <= 1 || **(argv + 1) == '-')
                usage(which_usage);
@@ -48,6 +48,7 @@
        while(argc-- > 0) {
                path_n = path_list;
                argv++;
+               found=FALSE;
                for (i = 0; i < count; i++) {
                        char buf[strlen(path_n)+1+strlen(*argv)];
                        strcpy (buf, path_n);
@@ -57,12 +58,16 @@
                            && filestat.st_mode & S_IXUSR)
                        {
                                printf ("%s\n", buf);
+                               found=TRUE;
                                break;
                        }
                        path_n += (strlen(path_n) + 1);
                }
+               if (found == FALSE) {
+                       status=EXIT_FAILURE
+               }
        }
-       return(TRUE);
+       return status;
 }

 /*

-- 
David Douthitt
UNIX Systems Administrator
HP-UX, Linux, Unixware
ddouthitt@mennonite.minister.net



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic