cfi new: fix new disabling buffer support
[barebox-mini2440.git] / commands / printenv.c
bloba7efd142cc6966611448fab8481ee073ed69f084
1 /*
2 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
4 * See file CREDITS for list of people who contributed to this
5 * project.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /**
22 * @file
23 * @brief printenv: Print out environment variables
26 #include <common.h>
27 #include <command.h>
28 #include <errno.h>
29 #include <environment.h>
31 static int do_printenv (cmd_tbl_t *cmdtp, int argc, char *argv[])
33 struct variable_d *var;
34 struct env_context *c, *current_c;
36 if (argc == 2) {
37 const char *val = getenv(argv[1]);
38 if (val) {
39 printf("%s=%s\n", argv[1], val);
40 return 0;
42 printf("## Error: \"%s\" not defined\n", argv[1]);
43 return 1;
46 current_c = get_current_context();
47 var = current_c->local->next;
48 printf("locals:\n");
49 while (var) {
50 printf("%s=%s\n", var_name(var), var_val(var));
51 var = var->next;
54 printf("globals:\n");
55 c = get_current_context();
56 while(c) {
57 var = c->global->next;
58 while (var) {
59 printf("%s=%s\n", var_name(var), var_val(var));
60 var = var->next;
62 c = c->parent;
65 return 0;
68 static const __maybe_unused char cmd_printenv_help[] =
69 "\n - print values of all environment variables\n"
70 "printenv name ...\n"
71 " - print value of environment variable 'name'\n";
74 U_BOOT_CMD_START(printenv)
75 .cmd = do_printenv,
76 .usage = "print environment variables",
77 U_BOOT_CMD_HELP(cmd_printenv_help)
78 U_BOOT_CMD_END
80 /**
81 * @page printenv_command printenv
83 * Usage: printenv [\<name>]
85 * Print environment variables.
86 * If \<name> was given, it prints out its content if the environment variable
87 * \<name> exists.
89 * Without the \<name> argument all current environment variables are printed.