summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-03-07 08:54:54 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-03-07 08:54:54 +0000
commit643af94b7afc643d06d26b0841c0d4d7fcc8591d (patch)
treec2ea9c25f1ceecf09f59efc8dd3670f68a47fb0e
parent1f76887d6028fbd1d6b40e0dec5a4565645c0f1e (diff)
Remove a couple duplicates entries that snuck in.
Per POSIX, if confstr() returns zero without setting errno ("no defined value") then print "undefined\n". Don't include a pointless number in the error messasge if confstr() fails. Above pointed out by Andres Perera (andres.p (at) zoho.com) Orgranize the CONFSTR code like the SYSCONF and PATHCONF cases. Don't test for confstr() returning (size_t)-1, as that's not special. Delete lint comments and unnecessary casts.
-rw-r--r--usr.bin/getconf/getconf.c51
1 files changed, 20 insertions, 31 deletions
diff --git a/usr.bin/getconf/getconf.c b/usr.bin/getconf/getconf.c
index 1632e30443b..c2a5378ecb4 100644
--- a/usr.bin/getconf/getconf.c
+++ b/usr.bin/getconf/getconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getconf.c,v 1.14 2013/03/02 07:18:17 jmc Exp $ */
+/* $OpenBSD: getconf.c,v 1.15 2013/03/07 08:54:53 guenther Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -161,7 +161,6 @@ const struct conf_variable conf_table[] =
posix2_pathconf_row(SYMLINKS)
constant_row(_POSIX2_CHARCLASS_NAME_MAX)
- constant_row(_POSIX2_RE_DUP_MAX)
constant_row(_XOPEN_IOV_MAX)
constant_row(_XOPEN_NAME_MAX)
constant_row(_XOPEN_PATH_MAX)
@@ -183,7 +182,6 @@ const struct conf_variable uposix_conf_table[] =
/*posix_constant_row(AIO_LISTIO_MAX)*/
/*posix_constant_row(AIO_MAX)*/
posix_constant_row(ARG_MAX)
- posix_constant_row(ARG_MAX)
posix_constant_row(CHILD_MAX)
/*posix_constant_row(DELAYTIMER_MAX)*/
posix_constant_row(HOST_NAME_MAX)
@@ -427,10 +425,8 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc < 1 || argc > 2) {
+ if (argc < 1 || argc > 2)
usage();
- /* NOTREACHED */
- }
/* pick a table based on a possible prefix */
if (strncmp(*argv, uposix_prefix, sizeof(uposix_prefix) - 1) == 0) {
@@ -465,10 +461,8 @@ main(int argc, char *argv[])
}
}
- if (cp->name == NULL) {
+ if (cp->name == NULL)
errx(1, "%s: unknown variable", *argv);
- /* NOTREACHED */
- }
if (cp->type == PATHCONF) {
if (argc != 2) usage();
@@ -483,30 +477,27 @@ main(int argc, char *argv[])
case CONFSTR:
errno = 0;
- slen = confstr (cp->value, (char *) 0, (size_t) 0);
-
- if (slen == 0 || slen == (size_t)-1) {
- if (errno)
- err(1, "%ld", cp->value);
- else
- errx(1, "%ld", cp->value);
- }
- if ((sval = malloc(slen)) == NULL)
- err(1, NULL);
+ if ((slen = confstr(cp->value, NULL, 0)) == 0) {
+ if (errno != 0)
+ err(1, NULL);
- confstr(cp->value, sval, slen);
- printf("%s\n", sval);
+ printf("undefined\n");
+ } else {
+ if ((sval = malloc(slen)) == NULL)
+ err(1, NULL);
+
+ confstr(cp->value, sval, slen);
+ printf("%s\n", sval);
+ }
break;
case SYSCONF:
errno = 0;
if ((val = sysconf(cp->value)) == -1) {
- if (errno != 0) {
+ if (errno != 0)
err(1, NULL);
- /* NOTREACHED */
- }
- printf ("undefined\n");
+ printf("undefined\n");
} else {
printf("%ld\n", val);
}
@@ -515,19 +506,17 @@ main(int argc, char *argv[])
case PATHCONF:
errno = 0;
if ((val = pathconf(argv[1], cp->value)) == -1) {
- if (errno != 0) {
+ if (errno != 0)
err(1, "%s", argv[1]);
- /* NOTREACHED */
- }
- printf ("undefined\n");
+ printf("undefined\n");
} else {
- printf ("%ld\n", val);
+ printf("%ld\n", val);
}
break;
}
- exit (ferror(stdout));
+ exit(ferror(stdout));
}