Tomasz Motylewski reported that the 'which' applet does not find
files when the full file PATH is specified. This patch from Arthur Othieno fixes it.
This commit is contained in:
parent
7f6295f516
commit
514633bf3f
@ -26,10 +26,19 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
|
static int file_exists(char *file)
|
||||||
|
{
|
||||||
|
struct stat filestat;
|
||||||
|
|
||||||
|
if (stat(file, &filestat) == 0 && filestat.st_mode & S_IXUSR)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
extern int which_main(int argc, char **argv)
|
extern int which_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *path_list, *path_n;
|
char *path_list, *path_n;
|
||||||
struct stat filestat;
|
|
||||||
int i, count=1, found, status = EXIT_SUCCESS;
|
int i, count=1, found, status = EXIT_SUCCESS;
|
||||||
|
|
||||||
if (argc <= 1 || **(argv + 1) == '-')
|
if (argc <= 1 || **(argv + 1) == '-')
|
||||||
@ -52,12 +61,20 @@ extern int which_main(int argc, char **argv)
|
|||||||
path_n = path_list;
|
path_n = path_list;
|
||||||
argv++;
|
argv++;
|
||||||
found = 0;
|
found = 0;
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if we were given the full path, first.
|
||||||
|
* Otherwise see if the file exists in our $PATH.
|
||||||
|
*/
|
||||||
|
buf = *argv;
|
||||||
|
if (file_exists(buf)) {
|
||||||
|
puts(buf);
|
||||||
|
found = 1;
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
buf = concat_path_file(path_n, *argv);
|
buf = concat_path_file(path_n, *argv);
|
||||||
if (stat (buf, &filestat) == 0
|
if (file_exists(buf)) {
|
||||||
&& filestat.st_mode & S_IXUSR)
|
|
||||||
{
|
|
||||||
puts(buf);
|
puts(buf);
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
@ -65,6 +82,7 @@ extern int which_main(int argc, char **argv)
|
|||||||
free(buf);
|
free(buf);
|
||||||
path_n += (strlen(path_n) + 1);
|
path_n += (strlen(path_n) + 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
status = EXIT_FAILURE;
|
status = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user