summaryrefslogtreecommitdiff
path: root/tools/env/fw_env.c
diff options
context:
space:
mode:
authorGrant Erickson <gerickson@nuovations.com>2008-05-06 20:16:15 -0700
committerWolfgang Denk <wd@denx.de>2008-05-09 23:40:40 +0200
commitbc11756daff89a3de09ca80adac962b88cf06e6e (patch)
tree9688c4851714884484c3e1834f272cb63e7b4cb6 /tools/env/fw_env.c
parentf3b6d528e4dd719640a4bfcd954f4e4c7f5db0d6 (diff)
Propagate Error Status to the Shell on fw_printenv Errors
Changed implementation such that fw_printenv returns failure status when one or more specified variables do not exist or when incorrect command syntax is used. This aids scripting fw_printenv such that the script can key of the return status rather than relying on standard error "scraping". Signed-off-by: Grant Erickson <gerickson@nuovations.com> Signed-off-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'tools/env/fw_env.c')
-rw-r--r--tools/env/fw_env.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index e083a5b11e..b8bca91c38 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1,5 +1,5 @@
/*
- * (C) Copyright 2000-2003
+ * (C) Copyright 2000-2008
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* See file CREDITS for list of people who contributed to this
@@ -209,13 +209,14 @@ char *fw_getenv (char *name)
* Print the current definition of one, or more, or all
* environment variables
*/
-void fw_printenv (int argc, char *argv[])
+int fw_printenv (int argc, char *argv[])
{
char *env, *nxt;
int i, n_flag;
+ int rc = 0;
if (env_init ())
- return;
+ return (-1);
if (argc == 1) { /* Print all env variables */
for (env = environment.data; *env; env = nxt + 1) {
@@ -223,13 +224,13 @@ void fw_printenv (int argc, char *argv[])
if (nxt >= &environment.data[ENV_SIZE]) {
fprintf (stderr, "## Error: "
"environment not terminated\n");
- return;
+ return (-1);
}
}
printf ("%s\n", env);
}
- return;
+ return (0);
}
if (strcmp (argv[1], "-n") == 0) {
@@ -239,7 +240,7 @@ void fw_printenv (int argc, char *argv[])
if (argc != 2) {
fprintf (stderr, "## Error: "
"`-n' option requires exactly one argument\n");
- return;
+ return (-1);
}
} else {
n_flag = 0;
@@ -255,7 +256,7 @@ void fw_printenv (int argc, char *argv[])
if (nxt >= &environment.data[ENV_SIZE]) {
fprintf (stderr, "## Error: "
"environment not terminated\n");
- return;
+ return (-1);
}
}
val = envmatch (name, env);
@@ -268,9 +269,13 @@ void fw_printenv (int argc, char *argv[])
break;
}
}
- if (!val)
+ if (!val) {
fprintf (stderr, "## Error: \"%s\" not defined\n", name);
+ rc = -1;
+ }
}
+
+ return (rc);
}
/*