#include <env_attr.h>
#include <env_flags.h>
#define getenv fw_getenv
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#else
#include <common.h>
#include <environment.h>
{
int i;
- for (i = 0; i < sizeof(env_flags_varaccess_mask); i++)
+ for (i = 0; i < ARRAY_SIZE(env_flags_varaccess_mask); i++)
if (env_flags_varaccess_mask[i] ==
(binflags & ENV_FLAGS_VARACCESS_BIN_MASK))
return (enum env_flags_varaccess)i;
*end = value;
}
+#ifdef CONFIG_CMD_NET
+int eth_validate_ethaddr_str(const char *addr)
+{
+ const char *end;
+ const char *cur;
+ int i;
+
+ cur = addr;
+ for (i = 0; i < 6; i++) {
+ skip_num(1, cur, &end, 2);
+ if (cur == end)
+ return -1;
+ if (cur + 2 == end && is_hex_prefix(cur))
+ return -1;
+ if (i != 5 && *end != ':')
+ return -1;
+ if (i == 5 && *end != '\0')
+ return -1;
+ cur = end + 1;
+ }
+
+ return 0;
+}
+#endif
+
/*
* Based on the declared type enum, validate that the value string complies
* with that format
}
break;
case env_flags_vartype_macaddr:
- cur = value;
- for (i = 0; i < 6; i++) {
- skip_num(1, cur, &end, 2);
- if (cur == end)
- return -1;
- if (cur + 2 == end && is_hex_prefix(cur))
- return -1;
- if (i != 5 && *end != ':')
- return -1;
- if (i == 5 && *end != '\0')
- return -1;
- cur = end + 1;
- }
+ if (eth_validate_ethaddr_str(value))
+ return -1;
break;
#endif
case env_flags_vartype_end:
/*
* Validate the parameters to "env set" directly
*/
-int env_flags_validate_env_set_params(int argc, char * const argv[])
+int env_flags_validate_env_set_params(char *name, char * const val[], int count)
{
- if ((argc >= 3) && argv[2] != NULL) {
- enum env_flags_vartype type = env_flags_get_type(argv[1]);
+ if ((count >= 1) && val[0] != NULL) {
+ enum env_flags_vartype type = env_flags_get_type(name);
/*
* we don't currently check types that need more than
* one argument
*/
- if (type != env_flags_vartype_string && argc > 3) {
- printf("## Error: too many parameters for setting "
- "\"%s\"\n", argv[1]);
+ if (type != env_flags_vartype_string && count > 1) {
+ printf("## Error: too many parameters for setting \"%s\"\n",
+ name);
return -1;
}
- return env_flags_validate_type(argv[1], argv[2]);
+ return env_flags_validate_type(name, val[0]);
}
/* ok */
return 0;
e.key = name;
e.data = NULL;
+ e.callback = NULL;
hsearch_r(e, FIND, &ep, &env_htab, 0);
/* does the env variable actually exist? */