2015-09-30 22:59:40 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct var {
|
|
|
|
const char *k;
|
|
|
|
long v;
|
|
|
|
};
|
|
|
|
|
2016-10-03 22:55:22 +00:00
|
|
|
#include "getconf.h"
|
2015-12-14 20:22:43 +00:00
|
|
|
|
2015-09-30 22:59:40 +00:00
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-12-15 08:43:55 +00:00
|
|
|
eprintf("usage: %s [-v spec] var [path]\n", argv0);
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
long res;
|
|
|
|
int i;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'v':
|
|
|
|
/* ignore */
|
2015-10-04 15:48:05 +00:00
|
|
|
EARGF(usage());
|
2015-09-30 22:59:40 +00:00
|
|
|
break;
|
2017-01-26 23:41:50 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
2015-11-01 10:16:49 +00:00
|
|
|
} ARGEND
|
2015-09-30 22:59:40 +00:00
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
/* sysconf */
|
|
|
|
for (i = 0; i < LEN(sysconf_l); i++) {
|
|
|
|
if (strcmp(argv[0], sysconf_l[i].k))
|
|
|
|
continue;
|
|
|
|
errno = 0;
|
|
|
|
if ((res = sysconf(sysconf_l[i].v)) < 0) {
|
|
|
|
if (errno)
|
|
|
|
eprintf("sysconf %ld:", sysconf_l[i].v);
|
|
|
|
puts("undefined");
|
|
|
|
} else {
|
|
|
|
printf("%ld\n", res);
|
|
|
|
}
|
2017-09-04 00:26:04 +00:00
|
|
|
return fshut(stdout, "<stdout>");
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|
|
|
|
/* confstr */
|
|
|
|
for (i = 0; i < LEN(confstr_l); i++) {
|
|
|
|
if (strcmp(argv[0], confstr_l[i].k))
|
|
|
|
continue;
|
|
|
|
errno = 0;
|
|
|
|
if (!(len = confstr(confstr_l[i].v, NULL, 0))) {
|
|
|
|
if (errno)
|
|
|
|
eprintf("confstr %ld:", confstr_l[i].v);
|
|
|
|
puts("undefined");
|
|
|
|
} else {
|
|
|
|
str = emalloc(len);
|
|
|
|
errno = 0;
|
|
|
|
if (!confstr(confstr_l[i].v, str, len)) {
|
|
|
|
if (errno)
|
|
|
|
eprintf("confstr %ld:", confstr_l[i].v);
|
|
|
|
puts("undefined");
|
|
|
|
} else {
|
|
|
|
puts(str);
|
|
|
|
}
|
|
|
|
free(str);
|
|
|
|
}
|
2017-09-04 00:26:04 +00:00
|
|
|
return fshut(stdout, "<stdout>");
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|
|
|
|
/* limits */
|
|
|
|
for (i = 0; i < LEN(limits_l); i++) {
|
|
|
|
if (strcmp(argv[0], limits_l[i].k))
|
|
|
|
continue;
|
|
|
|
printf("%ld\n", limits_l[i].v);
|
2017-09-04 00:26:04 +00:00
|
|
|
return fshut(stdout, "<stdout>");
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|
|
|
|
} else if (argc == 2) {
|
|
|
|
/* pathconf */
|
|
|
|
for (i = 0; i < LEN(pathconf_l); i++) {
|
|
|
|
if (strcmp(argv[0], pathconf_l[i].k))
|
|
|
|
continue;
|
|
|
|
errno = 0;
|
|
|
|
if ((res = pathconf(argv[1], pathconf_l[i].v)) < 0) {
|
|
|
|
if (errno)
|
|
|
|
eprintf("pathconf %ld:", pathconf_l[i].v);
|
|
|
|
puts("undefined");
|
|
|
|
} else {
|
|
|
|
printf("%ld\n", res);
|
|
|
|
}
|
2017-09-04 00:26:04 +00:00
|
|
|
return fshut(stdout, "<stdout>");
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2017-09-03 22:39:47 +00:00
|
|
|
eprintf("invalid variable: %s\n", argv[0]);
|
2020-03-02 00:38:14 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-09-30 22:59:40 +00:00
|
|
|
}
|