version 1.25, 2016/01/14 22:02:13 |
version 1.26, 2016/10/28 07:22:59 |
|
|
|
|
#include <err.h> |
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <locale.h> |
#include <limits.h> |
#include <paths.h> |
#include <paths.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <limits.h> |
|
|
|
#define PROG_WHICH 1 |
#define PROG_WHICH 1 |
#define PROG_WHEREIS 2 |
#define PROG_WHEREIS 2 |
|
|
extern char *__progname; |
extern char *__progname; |
|
|
int findprog(char *, char *, int, int); |
int findprog(char *, char *, int, int); |
__dead void usage(void); |
static void __dead usage(void); |
|
|
/* |
/* |
* which(1) -- find an executable(s) in the user's path |
* which(1) -- find an executable(s) in the user's path |
|
|
size_t n; |
size_t n; |
int ch, allmatches = 0, notfound = 0, progmode = PROG_WHICH; |
int ch, allmatches = 0, notfound = 0, progmode = PROG_WHICH; |
|
|
(void)setlocale(LC_ALL, ""); |
|
|
|
while ((ch = getopt(argc, argv, "a")) != -1) |
while ((ch = getopt(argc, argv, "a")) != -1) |
switch (ch) { |
switch (ch) { |
case 'a': |
case 'a': |
|
|
if (findprog(argv[n], path, progmode, allmatches) == 0) |
if (findprog(argv[n], path, progmode, allmatches) == 0) |
notfound++; |
notfound++; |
|
|
exit((notfound == 0) ? 0 : ((notfound == argc) ? 2 : 1)); |
return ((notfound == 0) ? 0 : ((notfound == argc) ? 2 : 1)); |
} |
} |
|
|
int |
int |
|
|
return (rval); |
return (rval); |
} |
} |
|
|
__dead void |
static void __dead |
usage(void) |
usage(void) |
{ |
{ |
(void)fprintf(stderr, "usage: %s [-a] name ...\n", __progname); |
(void)fprintf(stderr, "usage: %s [-a] name ...\n", __progname); |