nextbase -= ((CONFIG_ENV_SIZE + 4096 - 1) & ~(4096 - 1));
envp = (env_t *)nextbase;
res = (char *)envp->data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
*
* Returns 0 in case of error, or length of printed string
*/
-static int env_print(char *name)
+static int env_print(char *name, int flag)
{
char *res = NULL;
size_t len;
e.key = name;
e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
+ hsearch_r(e, FIND, &ep, &env_htab, flag);
if (ep == NULL)
return 0;
len = printf("%s=%s\n", ep->key, ep->data);
}
/* print whole list */
- len = hexport_r(&env_htab, '\n', &res, 0, 0, NULL);
+ len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
if (len > 0) {
puts(res);
{
int i;
int rcode = 0;
+ int env_flag = H_HIDE_DOT;
+
+ if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
+ argc--;
+ argv++;
+ env_flag &= ~H_HIDE_DOT;
+ }
if (argc == 1) {
/* print all env vars */
- rcode = env_print(NULL);
+ rcode = env_print(NULL, env_flag);
if (!rcode)
return 1;
printf("\nEnvironment size: %d/%ld bytes\n",
}
/* print selected env vars */
+ env_flag &= ~H_HIDE_DOT;
for (i = 1; i < argc; ++i) {
- int rc = env_print(argv[i]);
+ int rc = env_print(argv[i], env_flag);
if (!rc) {
printf("## Error: \"%s\" not defined\n", argv[i]);
++rcode;
argv++;
if (sep) { /* export as text file */
- len = hexport_r(&env_htab, sep, &addr, size, argc, argv);
+ len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
else /* export as raw binary data */
res = addr;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, argc, argv);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
#if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t | -b | -c] addr [size] - import environment\n"
#endif
- "env print [name ...] - print environment\n"
+ "env print [-a | name ...] - print environment\n"
#if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
#endif
U_BOOT_CMD_COMPLETE(
printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
"print environment variables",
- "\n - print values of all environment variables\n"
+ "[-a]\n - print [all] values of all environment variables\n"
"printenv name ...\n"
" - print value of environment variable 'name'",
var_complete
char *res;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
BUG_ON(env_ptr != NULL);
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
int err;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
goto done;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
goto done;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
}
res = (char *)&env_new->data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
ret = 1;
return 1;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
return 1;
res = (char *)&env_new->data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
int rcode = 0;
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
};
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
res = (char *)&env_new.data;
- len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+ len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
int __flag);
extern ssize_t hexport_r(struct hsearch_data *__htab,
- const char __sep, char **__resp, size_t __size,
+ const char __sep, int __flag, char **__resp, size_t __size,
int argc, char * const argv[]);
/*
const char *__env, size_t __size, const char __sep,
int __flag, int nvars, char * const vars[]);
-/* Flags for himport_r(), hdelete_r(), and hsearch_r() */
+/* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
#define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */
#define H_FORCE (1 << 1) /* overwrite read-only/write-once variables */
#define H_INTERACTIVE (1 << 2) /* indicate that an import is user directed */
+#define H_HIDE_DOT (1 << 3) /* don't print env vars that begin with '.' */
#endif /* search.h */
return (strcmp(e1->key, e2->key));
}
-ssize_t hexport_r(struct hsearch_data *htab, const char sep,
+ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
char **resp, size_t size,
int argc, char * const argv[])
{
if ((argc > 0) && (found == 0))
continue;
+ if ((flag & H_HIDE_DOT) && ep->key[0] == '.')
+ continue;
+
list[n++] = ep;
totlen += strlen(ep->key) + 2;