version 1.11, 2003/06/17 21:56:26 |
version 1.12, 2004/09/23 17:44:47 |
|
|
extern char *__progname; |
extern char *__progname; |
|
|
int findprog(char *, char *, int, int); |
int findprog(char *, char *, int, int); |
void usage(void); |
__dead void usage(void); |
|
|
/* |
/* |
* which(1) -- find an executable(s) in the user's path |
* which(1) -- find an executable(s) in the user's path |
|
|
if ((stat(prog, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && |
if ((stat(prog, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && |
access(prog, X_OK) == 0) { |
access(prog, X_OK) == 0) { |
(void)puts(prog); |
(void)puts(prog); |
return(1); |
return (1); |
} else { |
} else { |
(void)printf("%s: Command not found.\n", prog); |
(void)printf("%s: Command not found.\n", prog); |
return(0); |
return (0); |
} |
} |
} |
} |
|
|
|
|
|
|
if (plen + 1 + proglen >= sizeof(filename)) { |
if (plen + 1 + proglen >= sizeof(filename)) { |
warnx("%s/%s: %s", p, prog, strerror(ENAMETOOLONG)); |
warnx("%s/%s: %s", p, prog, strerror(ENAMETOOLONG)); |
return(0); |
free(path); |
|
return (0); |
} |
} |
|
|
snprintf(filename, sizeof(filename), "%s/%s", p, prog); |
snprintf(filename, sizeof(filename), "%s/%s", p, prog); |
|
|
access(filename, X_OK) == 0) { |
access(filename, X_OK) == 0) { |
(void)puts(filename); |
(void)puts(filename); |
rval = 1; |
rval = 1; |
if (!allmatches) |
if (!allmatches) { |
return(rval); |
free(path); |
|
return (rval); |
|
} |
} |
} |
} |
} |
(void)free(path); |
(void)free(path); |
|
|
/* whereis(1) is silent on failure. */ |
/* whereis(1) is silent on failure. */ |
if (!rval && progmode != PROG_WHEREIS) |
if (!rval && progmode != PROG_WHEREIS) |
(void)printf("%s: Command not found.\n", prog); |
(void)printf("%s: Command not found.\n", prog); |
return(rval); |
return (rval); |
} |
} |
|
|
void |
__dead void |
usage(void) |
usage(void) |
{ |
{ |
(void) fprintf(stderr, "Usage: %s [-a] name [...]\n", __progname); |
(void) fprintf(stderr, "Usage: %s [-a] name [...]\n", __progname); |