File: which.c

package info (click to toggle)
libite 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,188 kB
  • sloc: sh: 4,665; ansic: 4,165; makefile: 141
file content (49 lines) | stat: -rw-r--r-- 908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "check.h"

struct tc {
	char *cmd;
	int   exp;
	int   res;
};

int main(void)
{
	int result = 0;
	size_t i;
	struct tc test[] = {
		{ "executable",      1, 0 },
		{ "executable -h",   1, 0 },
		{ "executable-link", 1, 0 },
		{ "regular",         0, 0 },
		{ "ls",              1, 0 },
		{ "/usr/bin/which",  1, 0 },
		{ NULL, 0, 0 }
	};

	setenv("PATH", "data/which:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin", 1);
	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:
 */