2000-05-19 05:35:19 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Which implementation for busybox
|
|
|
|
*
|
2001-01-27 09:33:39 +00:00
|
|
|
* Copyright (C) 1999,2000,2001 by Lineo, inc.
|
2000-05-19 05:35:19 +00:00
|
|
|
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-03-09 21:28:09 +00:00
|
|
|
/* getopt not needed */
|
2001-01-27 08:24:39 +00:00
|
|
|
#include <string.h>
|
2000-05-19 05:35:19 +00:00
|
|
|
#include <stdio.h>
|
2001-01-27 08:24:39 +00:00
|
|
|
#include <stdlib.h>
|
2001-02-20 06:14:08 +00:00
|
|
|
#include "busybox.h"
|
2000-05-19 05:35:19 +00:00
|
|
|
|
|
|
|
extern int which_main(int argc, char **argv)
|
|
|
|
{
|
2000-09-18 09:37:40 +00:00
|
|
|
char *path_list, *path_n;
|
2000-06-05 23:41:27 +00:00
|
|
|
struct stat filestat;
|
2000-11-18 01:16:43 +00:00
|
|
|
int i, count=1, found, status = EXIT_SUCCESS;
|
2000-05-19 05:35:19 +00:00
|
|
|
|
2000-07-14 23:28:47 +00:00
|
|
|
if (argc <= 1 || **(argv + 1) == '-')
|
2001-02-14 21:23:06 +00:00
|
|
|
show_usage();
|
2000-05-19 05:35:19 +00:00
|
|
|
argc--;
|
|
|
|
|
|
|
|
path_list = getenv("PATH");
|
|
|
|
if (!path_list)
|
|
|
|
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
|
|
|
|
|
2000-06-05 23:41:27 +00:00
|
|
|
/* Replace colons with zeros in path_parsed and count them */
|
2000-09-18 09:37:40 +00:00
|
|
|
for(i=strlen(path_list); i > 0; i--)
|
|
|
|
if (path_list[i]==':') {
|
|
|
|
path_list[i]=0;
|
|
|
|
count++;
|
|
|
|
}
|
2000-06-05 23:41:27 +00:00
|
|
|
|
|
|
|
while(argc-- > 0) {
|
2000-09-18 09:37:40 +00:00
|
|
|
path_n = path_list;
|
2000-06-05 23:41:27 +00:00
|
|
|
argv++;
|
2000-11-18 01:16:43 +00:00
|
|
|
found = 0;
|
2000-06-05 23:41:27 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2000-09-18 09:37:40 +00:00
|
|
|
char buf[strlen(path_n)+1+strlen(*argv)];
|
|
|
|
strcpy (buf, path_n);
|
2000-06-05 23:41:27 +00:00
|
|
|
strcat (buf, "/");
|
|
|
|
strcat (buf, *argv);
|
|
|
|
if (stat (buf, &filestat) == 0
|
|
|
|
&& filestat.st_mode & S_IXUSR)
|
|
|
|
{
|
2000-09-18 09:37:40 +00:00
|
|
|
printf ("%s\n", buf);
|
2000-11-18 01:16:43 +00:00
|
|
|
found = 1;
|
2000-06-05 23:41:27 +00:00
|
|
|
break;
|
2000-05-19 05:35:19 +00:00
|
|
|
}
|
2000-09-18 09:37:40 +00:00
|
|
|
path_n += (strlen(path_n) + 1);
|
2000-05-19 05:35:19 +00:00
|
|
|
}
|
2000-11-18 01:16:43 +00:00
|
|
|
if (!found)
|
|
|
|
status = EXIT_FAILURE;
|
2000-05-19 05:35:19 +00:00
|
|
|
}
|
2000-11-18 01:16:43 +00:00
|
|
|
return status;
|
2000-05-19 05:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
c-file-style: "linux"
|
|
|
|
c-basic-offset: 4
|
|
|
|
tab-width: 4
|
|
|
|
End:
|
|
|
|
*/
|