summaryrefslogtreecommitdiffstats
path: root/tests/helpers/test_pathnames.c
blob: 594f458335560a54ef24690491723616f3a4df93 (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2007 Karel Zak <kzak@redhat.com>
 *
 * This file is part of util-linux-ng.
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This file is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "pathnames.h"

struct hlpPath
{
	const char *name;
	const char *path;
};

#define DEF_HLPPATH(_p)		{ #_p, _p }

struct hlpPath paths[] =
{
	DEF_HLPPATH(_PATH_DEFPATH),
	DEF_HLPPATH(_PATH_DEFPATH_ROOT),
	DEF_HLPPATH(_PATH_TTY),
	DEF_HLPPATH(_PATH_SECURETTY),
	DEF_HLPPATH(_PATH_WTMPLOCK),
	DEF_HLPPATH(_PATH_HUSHLOGIN),
	DEF_HLPPATH(_PATH_MAILDIR),
	DEF_HLPPATH(_PATH_MOTDFILE),
	DEF_HLPPATH(_PATH_NOLOGIN),
	DEF_HLPPATH(_PATH_LOGIN),
	DEF_HLPPATH(_PATH_INITTAB),
	DEF_HLPPATH(_PATH_RC),
	DEF_HLPPATH(_PATH_REBOOT),
	DEF_HLPPATH(_PATH_SINGLE),
	DEF_HLPPATH(_PATH_SHUTDOWN_CONF),
	DEF_HLPPATH(_PATH_SECURE),
	DEF_HLPPATH(_PATH_USERTTY),
	DEF_HLPPATH(_PATH_MTAB),
	DEF_HLPPATH(_PATH_UMOUNT),
	DEF_HLPPATH(_PATH_PASSWD),
	DEF_HLPPATH(_PATH_GSHADOW),
	DEF_HLPPATH(_PATH_PTMP),
	DEF_HLPPATH(_PATH_PTMPTMP),
	DEF_HLPPATH(_PATH_GROUP),
	DEF_HLPPATH(_PATH_GTMP),
	DEF_HLPPATH(_PATH_GTMPTMP),
	DEF_HLPPATH(_PATH_SHADOW_PASSWD),
	DEF_HLPPATH(_PATH_SHADOW_PTMP),
	DEF_HLPPATH(_PATH_SHADOW_PTMPTMP),
	DEF_HLPPATH(_PATH_SHADOW_GROUP),
	DEF_HLPPATH(_PATH_SHADOW_GTMP),
	DEF_HLPPATH(_PATH_SHADOW_GTMPTMP),
	DEF_HLPPATH(_PATH_WORDS),
	DEF_HLPPATH(_PATH_WORDS_ALT),
	{ NULL, NULL }
};

int
main(int argc, char **argv)
{
	struct hlpPath *p;

	if (argc == 1) {
		for (p = paths; p->name; p++)
			printf("%20s %s\n", p->name, p->path);
		exit(EXIT_SUCCESS);
	} else {
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
			printf("%s <option>\n", argv[0]);
			fputs("options:\n", stdout);
			for (p = paths; p->name; p++)
				printf("\t%s\n", p->name);
			exit(EXIT_SUCCESS);
		}

		for (p = paths; p->name; p++) {
			if (strcmp(p->name, argv[1]) == 0) {
				printf("%s\n", p->path);
				exit(EXIT_SUCCESS);
			}
		}
	}

	exit(EXIT_FAILURE);
}