Discussion:
[PATCH] getconf: say "undefined" for sysconf/pathconf -1.
(too old to reply)
enh
2018-10-05 22:30:55 UTC
Permalink
---
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
Rob Landley
2018-10-07 15:32:10 UTC
Permalink
Sigh, window got buried instead of sent, sorry if this is a duplicate...
Post by enh
+static void printconf(long v)
+{
+ if (v == -1) puts("undefined");
+ else printf("%ld\n", v);
+}
+
...
Post by enh
- 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));
New function called twice, doesn't need to be called twice...

I pulled this into some cleanups I was poking at locally (help text tweak, made
the goto go away, curly brackets, etc).

Rob

Loading...