- minor shrinkage
This commit is contained in:
parent
d760560c52
commit
66e3a222cd
@ -16,9 +16,15 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
|
static int is_executable_file(const char const * a, struct stat *b)
|
||||||
|
{
|
||||||
|
return (!access(a,X_OK) && !stat(a, b) && S_ISREG(b->st_mode));
|
||||||
|
}
|
||||||
|
|
||||||
int which_main(int argc, char **argv)
|
int which_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status = EXIT_SUCCESS;
|
int status;
|
||||||
size_t i, count;
|
size_t i, count;
|
||||||
char *path_list;
|
char *path_list;
|
||||||
|
|
||||||
@ -63,13 +69,12 @@ int which_main(int argc, char **argv)
|
|||||||
count = 5;
|
count = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = EXIT_SUCCESS;
|
||||||
while (argc-- > 0) {
|
while (argc-- > 0) {
|
||||||
struct stat stat_b;
|
struct stat stat_b;
|
||||||
char *buf;
|
char *buf;
|
||||||
char *path_n;
|
char *path_n;
|
||||||
char found = 0;
|
int found = 0;
|
||||||
#define is_executable_file(a, b) (!access(a,X_OK) && !stat(a, &b) && \
|
|
||||||
S_ISREG(b.st_mode))
|
|
||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
path_n = path_list;
|
path_n = path_list;
|
||||||
@ -77,14 +82,14 @@ int which_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* if filename is either absolute or contains slashes,
|
/* if filename is either absolute or contains slashes,
|
||||||
* stat it */
|
* stat it */
|
||||||
if (strchr(buf, '/') != NULL && is_executable_file(buf, stat_b)) {
|
if (strchr(buf, '/') != NULL && is_executable_file(buf, &stat_b)) {
|
||||||
found = 1;
|
found++;
|
||||||
} else {
|
} else {
|
||||||
/* Couldn't access file and file doesn't contain slashes */
|
/* Couldn't access file and file doesn't contain slashes */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
buf = concat_path_file(path_n, *argv);
|
buf = concat_path_file(path_n, *argv);
|
||||||
if (is_executable_file(buf, stat_b)) {
|
if (is_executable_file(buf, &stat_b)) {
|
||||||
found = 1;
|
found++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user