blob: d927f2dc5c4936af0e532fa88d24b7839b92e295 [file] [log] [blame]
FRIGN05996b92015-10-01 00:59:40 +02001/* See LICENSE file for copyright and license details. */
2#include <errno.h>
3#include <unistd.h>
4#include <limits.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include "util.h"
9
10struct var {
11 const char *k;
12 long v;
13};
14
Evan Gatesde28c8b2016-10-03 15:55:22 -070015#include "getconf.h"
Roberto E. Vargas Caballero136f0122015-12-14 21:22:43 +010016
FRIGN05996b92015-10-01 00:59:40 +020017void
18usage(void)
19{
sinc0eafd42015-12-15 08:43:55 +000020 eprintf("usage: %s [-v spec] var [path]\n", argv0);
FRIGN05996b92015-10-01 00:59:40 +020021}
22
23int
24main(int argc, char *argv[])
25{
26 size_t len;
27 long res;
28 int i;
29 char *str;
30
31 ARGBEGIN {
32 case 'v':
33 /* ignore */
sin34237522015-10-04 16:48:05 +010034 EARGF(usage());
FRIGN05996b92015-10-01 00:59:40 +020035 break;
Mattias Andréed3013222017-01-27 00:41:50 +010036 default:
37 usage();
38 break;
sin23661642015-11-01 10:16:49 +000039 } ARGEND
FRIGN05996b92015-10-01 00:59:40 +020040
41 if (argc == 1) {
42 /* sysconf */
43 for (i = 0; i < LEN(sysconf_l); i++) {
44 if (strcmp(argv[0], sysconf_l[i].k))
45 continue;
46 errno = 0;
47 if ((res = sysconf(sysconf_l[i].v)) < 0) {
48 if (errno)
49 eprintf("sysconf %ld:", sysconf_l[i].v);
50 puts("undefined");
51 } else {
52 printf("%ld\n", res);
53 }
54 return 0;
55 }
56 /* confstr */
57 for (i = 0; i < LEN(confstr_l); i++) {
58 if (strcmp(argv[0], confstr_l[i].k))
59 continue;
60 errno = 0;
61 if (!(len = confstr(confstr_l[i].v, NULL, 0))) {
62 if (errno)
63 eprintf("confstr %ld:", confstr_l[i].v);
64 puts("undefined");
65 } else {
66 str = emalloc(len);
67 errno = 0;
68 if (!confstr(confstr_l[i].v, str, len)) {
69 if (errno)
70 eprintf("confstr %ld:", confstr_l[i].v);
71 puts("undefined");
72 } else {
73 puts(str);
74 }
75 free(str);
76 }
77 return 0;
78 }
79 /* limits */
80 for (i = 0; i < LEN(limits_l); i++) {
81 if (strcmp(argv[0], limits_l[i].k))
82 continue;
83 printf("%ld\n", limits_l[i].v);
84 return 0;
85 }
86 } else if (argc == 2) {
87 /* pathconf */
88 for (i = 0; i < LEN(pathconf_l); i++) {
89 if (strcmp(argv[0], pathconf_l[i].k))
90 continue;
91 errno = 0;
92 if ((res = pathconf(argv[1], pathconf_l[i].v)) < 0) {
93 if (errno)
94 eprintf("pathconf %ld:", pathconf_l[i].v);
95 puts("undefined");
96 } else {
97 printf("%ld\n", res);
98 }
99 return 0;
100 }
101 } else {
102 usage();
103 }
104
105 puts("undefined");
106
107 return 1;
108}
OSZAR »