int setenv(const char *varname, const char *varvalue) { const char * const argv[4] = { "setenv", varname, varvalue, NULL }; /* before import into hashtable */ if (!(gd->flags & GD_FLG_ENV_READY)) return 1; if (varvalue == NULL || varvalue[0] == '\0') return _do_env_set(0, 2, (char * const *)argv); else return _do_env_set(0, 3, (char * const *)argv); }
int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) return cmd_usage(cmdtp); return _do_env_set(flag, argc, argv); }
static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) return CMD_RET_USAGE; return _do_env_set(flag, argc, argv); }
int do_setenv(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) return 1; return _do_env_set(flag, argc, argv); }
int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { extern char console_buffer[CONFIG_SYS_CBSIZE]; char message[CONFIG_SYS_CBSIZE]; int size = CONFIG_SYS_CBSIZE - 1; int i, len, pos; char *local_args[4]; local_args[0] = argv[0]; local_args[1] = argv[1]; local_args[2] = NULL; local_args[3] = NULL; /* Check the syntax */ switch (argc) { case 1: return cmd_usage(cmdtp); case 2: /* env_ask envname */ sprintf(message, "Please enter '%s':", argv[1]); break; case 3: /* env_ask envname size */ sprintf(message, "Please enter '%s':", argv[1]); size = simple_strtoul(argv[2], NULL, 10); break; default: /* env_ask envname message1 ... messagen size */ for (i = 2, pos = 0; i < argc - 1; i++) { if (pos) message[pos++] = ' '; strcpy(message+pos, argv[i]); pos += strlen(argv[i]); } message[pos] = '\0'; size = simple_strtoul(argv[argc - 1], NULL, 10); break; } if (size >= CONFIG_SYS_CBSIZE) size = CONFIG_SYS_CBSIZE - 1; if (size <= 0) return 1; /* prompt for input */ len = readline(message); if (size < len) console_buffer[size] = '\0'; len = 2; if (console_buffer[0] != '\0') { local_args[2] = console_buffer; len = 3; } /* Continue calling setenv code */ return _do_env_set(flag, len, local_args); }
int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char message[CONFIG_SYS_CBSIZE]; int i, len, pos, size; char *local_args[4]; char *endptr; local_args[0] = argv[0]; local_args[1] = argv[1]; local_args[2] = NULL; local_args[3] = NULL; /* * Check the syntax: * * env_ask envname [message1 ...] [size] */ if (argc == 1) return CMD_RET_USAGE; /* * We test the last argument if it can be converted * into a decimal number. If yes, we assume it's * the size. Otherwise we echo it as part of the * message. */ i = simple_strtoul(argv[argc - 1], &endptr, 10); if (*endptr != '\0') { /* no size */ size = CONFIG_SYS_CBSIZE - 1; } else { /* size given */ size = i; --argc; } if (argc <= 2) { sprintf(message, "Please enter '%s': ", argv[1]); } else { /* env_ask envname message1 ... messagen [size] */ for (i = 2, pos = 0; i < argc; i++) { if (pos) message[pos++] = ' '; strcpy(message + pos, argv[i]); pos += strlen(argv[i]); } message[pos++] = ' '; message[pos] = '\0'; } if (size >= CONFIG_SYS_CBSIZE) size = CONFIG_SYS_CBSIZE - 1; if (size <= 0) return 1; /* prompt for input */ len = readline(message); if (size < len) console_buffer[size] = '\0'; len = 2; if (console_buffer[0] != '\0') { local_args[2] = console_buffer; len = 3; } /* Continue calling setenv code */ return _do_env_set(flag, len, local_args); }