enh
2018-10-05 22:30:55 UTC
---
toys/posix/getconf.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/toys/posix/getconf.c b/toys/posix/getconf.c
index d10365b..38c74d5 100644
--- a/toys/posix/getconf.c
+++ b/toys/posix/getconf.c
@@ -140,6 +140,12 @@ struct config others[] = {
{"LFS_CFLAGS", 0}, {"LFS_LDFLAGS", 0}, {"LFS_LIBS", 0}
};
+static void printconf(long v)
+{
+ if (v == -1) puts("undefined");
+ else printf("%ld\n", v);
+}
+
void getconf_main(void)
{
struct config *configs[] = {sysconfs, pathconfs, confstrs, limits, others},
@@ -178,8 +184,8 @@ void getconf_main(void)
if (toys.optc!=2) help_exit("%s needs a path", name);
} else if (toys.optc!=1) help_exit("%s does not take a path", name);
- if (!i) printf("%ld\n", sysconf(c->value));
- else if (i==1) printf("%ld\n", pathconf(toys.optargs[1], c->value));
+ if (!i) printconf(sysconf(c->value));
+ else if (i==1) printconf(pathconf(toys.optargs[1], c->value));
else if (i==2) {
confstr(c->value, toybuf, sizeof(toybuf));
puts(toybuf);
toys/posix/getconf.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/toys/posix/getconf.c b/toys/posix/getconf.c
index d10365b..38c74d5 100644
--- a/toys/posix/getconf.c
+++ b/toys/posix/getconf.c
@@ -140,6 +140,12 @@ struct config others[] = {
{"LFS_CFLAGS", 0}, {"LFS_LDFLAGS", 0}, {"LFS_LIBS", 0}
};
+static void printconf(long v)
+{
+ if (v == -1) puts("undefined");
+ else printf("%ld\n", v);
+}
+
void getconf_main(void)
{
struct config *configs[] = {sysconfs, pathconfs, confstrs, limits, others},
@@ -178,8 +184,8 @@ void getconf_main(void)
if (toys.optc!=2) help_exit("%s needs a path", name);
} else if (toys.optc!=1) help_exit("%s does not take a path", name);
- if (!i) printf("%ld\n", sysconf(c->value));
- else if (i==1) printf("%ld\n", pathconf(toys.optargs[1], c->value));
+ if (!i) printconf(sysconf(c->value));
+ else if (i==1) printconf(pathconf(toys.optargs[1], c->value));
else if (i==2) {
confstr(c->value, toybuf, sizeof(toybuf));
puts(toybuf);
--
2.19.0.605.g01d371f741-goog
2.19.0.605.g01d371f741-goog