From 0ba371384f4d46ca7d00b73a3ade4420910bb1cf Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 6 Oct 2018 22:18:52 -0500 Subject: Say undefined for sysconf/pathconf -1, remove goto, help text tweak, remove curly brackets around single line if(). --- toys/posix/getconf.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'toys/posix/getconf.c') diff --git a/toys/posix/getconf.c b/toys/posix/getconf.c index d10365b5..5e3e08af 100644 --- a/toys/posix/getconf.c +++ b/toys/posix/getconf.c @@ -5,6 +5,7 @@ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getconf.c * * Deviations from posix: no -v because nothing says what it should DO. + * Added -l, what symbols should be included is a bit unclear USE_GETCONF(NEWTOY(getconf, ">2l", TOYFLAG_USR|TOYFLAG_BIN)) @@ -12,9 +13,7 @@ config GETCONF bool "getconf" default y help - usage: getconf -l - usage: getconf NAME - usage: getconf NAME PATH + usage: getconf -l | NAME [PATH] Get system configuration values. Values from pathconf(3) require a path. @@ -135,7 +134,7 @@ struct config limits[] = { CONF(_POSIX2_EXPR_NEST_MAX), CONF(_POSIX2_LINE_MAX), CONF(_POSIX2_RE_DUP_MAX) }; -// Names that default to blank +// Names we need to handle ourselves (default to blank but shouldn't error) struct config others[] = { {"LFS_CFLAGS", 0}, {"LFS_LDFLAGS", 0}, {"LFS_LIBS", 0} }; @@ -152,9 +151,7 @@ void getconf_main(void) if (toys.optflags&FLAG_l) { for (i = 0; i<5; i++) { printf("%s\n", config_names[i]); - for (j = 0; jname, name)) goto found; + if (!strcmp(c->name, name)) break; } - error_msg("bad '%s'", name); - found: // Check that we do/don't have the extra path argument. if (i==1) { 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<2) { + long l = i ? pathconf(toys.optargs[1], c->value) : sysconf(c->value); + + if (l == -1) puts("undefined"); + else printf("%ld\n", l); + } else if (i==1) printf("%ld\n", pathconf(toys.optargs[1], c->value)); else if (i==2) { confstr(c->value, toybuf, sizeof(toybuf)); puts(toybuf); } else if (i==3) printf("%d\n", c->value); - // For legacy kernel build - else if (sizeof(long)==4 && !j) { + // LFS_CFLAGS on 32 bit should enable Large File Support (kernel build cares) + else if (sizeof(long)==4 && !j) puts("-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"); - } } -- cgit v1.2.3