mirror of
https://github.com/troglobit/libite.git
synced 2026-10-27 12:11:06 +00:00
which.c: C implementation of UNIX which(1)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
0d70c116d7
commit
d018a5215f
7 files changed
+146
-1
No files matched your search
@@ -14,3 +14,4 @@ rsync
|
||||
tempfile
|
||||
touch
|
||||
tree
|
||||
which
|
||||
@@ -16,6 +16,7 @@ TESTS += progress
|
||||
TESTS += rsync
|
||||
TESTS += tempfile
|
||||
TESTS += tree
|
||||
TESTS += which
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "check.h"
|
||||
|
||||
struct tc {
|
||||
char *cmd;
|
||||
int exp;
|
||||
int res;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int result = 0;
|
||||
size_t i;
|
||||
struct tc test[] = {
|
||||
{ "ls", 1 },
|
||||
{ "free", 1 },
|
||||
{ "modinfo", 1 },
|
||||
{ "useradd", 1 },
|
||||
{ "/etc/passwd", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
for (i = 0; test[i].cmd; i++) {
|
||||
char *path;
|
||||
|
||||
path = which(test[i].cmd);
|
||||
if (!path) {
|
||||
test[i].res = 0;
|
||||
fprintf(stderr, "%20s : Not hot dog\n", test[i].cmd);
|
||||
} else {
|
||||
test[i].res = 1;
|
||||
fprintf(stderr, "%20s : hot dog --> %s\n", test[i].cmd, path);
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; test[i].cmd; i++)
|
||||
result += test[i].exp != test[i].res;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
Reference in new issue
Block a user