summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorscf <scf@FreeBSD.org>2008-03-01 00:02:12 +0000
committerscf <scf@FreeBSD.org>2008-03-01 00:02:12 +0000
commit39b88b271ad223e72019371777d52d9be1e5666b (patch)
treecb2790089caddf964b7e1b45757fb50e9ecb3a02 /tools
parentc2409b54371e73585a34e2b232d099cd8e347f23 (diff)
downloadFreeBSD-src-39b88b271ad223e72019371777d52d9be1e5666b.zip
FreeBSD-src-39b88b271ad223e72019371777d52d9be1e5666b.tar.gz
Remove a dereference. It was unintended and a no-op.
Use the correct value of errno. Although the errno value passed into printf() follows the *env() call, it is not guaranteed to be the errno from that call. When I wrote the regression tester, the environment I used did pass the errno from the call. Consolidate the print for the return code and errno into a function in the process of fixing this. Approved by: wes (mentor)
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/environ/envctl.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/tools/regression/environ/envctl.c b/tools/regression/environ/envctl.c
index e077e42..a63270d 100644
--- a/tools/regression/environ/envctl.c
+++ b/tools/regression/environ/envctl.c
@@ -39,18 +39,24 @@ __FBSDID("$FreeBSD$");
extern char **environ;
+/*
+ * Print entire environ array.
+ */
static void
dump_environ(void)
{
char **environPtr;
- for (environPtr = environ; *environPtr != NULL; *environPtr++)
+ for (environPtr = environ; *environPtr != NULL; environPtr++)
printf("%s\n", *environPtr);
return;
}
+/*
+ * Print usage.
+ */
static void
usage(const char *program)
{
@@ -76,6 +82,19 @@ usage(const char *program)
}
+/*
+ * Print the return value of a call along with errno upon error else zero.
+ * Also, use the eol string based upon whether running in test mode or not.
+ */
+static void
+print_rtrn_errno(int rtrnVal, const char *eol)
+{
+ printf("%d %d%s", rtrnVal, rtrnVal != 0 ? errno : 0, eol);
+
+ return;
+}
+
+
int
main(int argc, char **argv)
{
@@ -89,6 +108,7 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ /* The entire program is basically executed from this loop. */
while ((arg = getopt(argc, argv, "CDGS:Ucg:hp:rs:tu:")) != -1) {
switch (arg) {
case 'C':
@@ -100,23 +120,17 @@ main(int argc, char **argv)
break;
case 'D':
- errno = 0;
dump_environ();
break;
case 'G':
- value = getenv(NULL);
- printf("%s%s", value == NULL ? "" : value, eol);
- break;
-
case 'g':
- value = getenv(optarg);
+ value = getenv(arg == 'g' ? optarg : NULL);
printf("%s%s", value == NULL ? "" : value, eol);
break;
case 'p':
- errno = 0;
- printf("%d %d%s", putenv(optarg), errno, eol);
+ print_rtrn_errno(putenv(optarg), eol);
break;
case 'r':
@@ -124,16 +138,14 @@ main(int argc, char **argv)
break;
case 'S':
- errno = 0;
- printf("%d %d%s", setenv(NULL, optarg,
- atoi(argv[optind])), errno, eol);
+ print_rtrn_errno(setenv(NULL, optarg,
+ atoi(argv[optind])), eol);
optind += 1;
break;
case 's':
- errno = 0;
- printf("%d %d%s", setenv(optarg, argv[optind],
- atoi(argv[optind + 1])), errno, eol);
+ print_rtrn_errno(setenv(optarg, argv[optind],
+ atoi(argv[optind + 1])), eol);
optind += 2;
break;
@@ -142,11 +154,9 @@ main(int argc, char **argv)
break;
case 'U':
- printf("%d %d%s", unsetenv(NULL), errno, eol);
- break;
-
case 'u':
- printf("%d %d%s", unsetenv(optarg), errno, eol);
+ print_rtrn_errno(unsetenv(arg == 'u' ? optarg :
+ NULL), eol);
break;
case 'h':
@@ -156,7 +166,7 @@ main(int argc, char **argv)
}
}
- // Output a closing newline in test mode.
+ /* Output a closing newline in test mode. */
if (eol[0] == ' ')
printf("\n");
OpenPOWER on IntegriCloud