[Toybox] [PATCH] getconf: say "undefined" for sysconf/pathconf -1.

enh enh at google.com
Fri Oct 5 15:30:55 PDT 2018


---
 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-getconf-say-undefined-for-sysconf-pathconf-1.patch
Type: text/x-patch
Size: 1291 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20181005/27938d6f/attachment-0002.bin>


More information about the Toybox mailing list