Chris PeBenito 473ea7
#include <unistd.h>
Chris PeBenito 473ea7
#include <stdio.h>
Chris PeBenito 473ea7
#include <stdlib.h>
Chris PeBenito 473ea7
#include <getopt.h>
Chris PeBenito 473ea7
#include <selinux/selinux.h>
Chris PeBenito 473ea7
Chris PeBenito 473ea7
void usage(const char *progname) 
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	fprintf(stderr, "usage:  %s [-n] path...\n", progname);
Chris PeBenito 473ea7
	exit(1);
Chris PeBenito 473ea7
}
Chris PeBenito 473ea7
Chris PeBenito 473ea7
int main(int argc, char **argv) 
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	char *buf;
Chris PeBenito 473ea7
	int rc, i;
Chris PeBenito 473ea7
	int header=1, opt;
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	if (argc < 2) usage(argv[0]);
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	while ((opt = getopt(argc, argv, "n")) > 0) {
Chris PeBenito 473ea7
		switch (opt) {
Chris PeBenito 473ea7
		case 'n':
Chris PeBenito 473ea7
			header=0;
Chris PeBenito 473ea7
			break;
Chris PeBenito 473ea7
		default:
Chris PeBenito 473ea7
			usage(argv[0]);
Chris PeBenito 473ea7
		}
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
	for (i = optind; i < argc; i++) {
Chris PeBenito 473ea7
		rc = matchpathcon(argv[i], 0, &buf;;
Chris PeBenito 473ea7
		if (rc < 0) {
Chris PeBenito 473ea7
			fprintf(stderr, "%s:  matchpathcon(%s) failed\n", argv[0], argv[i]);
Chris PeBenito 473ea7
			return 2;
Chris PeBenito 473ea7
		}
Chris PeBenito 473ea7
		if (header)
Chris PeBenito 473ea7
			printf("%s\t%s\n", argv[i], buf);
Chris PeBenito 473ea7
		else
Chris PeBenito 473ea7
			printf("%s\n", buf);
Chris PeBenito 473ea7
Chris PeBenito 473ea7
		freecon(buf);
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
	return 0;
Chris PeBenito 473ea7
}