U-Boot is not supposed to use typedef for structs anymore. Also this name
is the same as the ENTRY() macro used in assembler files, and 'entry'
itself is widely used in U-Boot (>8k matches).
Drop the typedef and rename the struct to env_entry to reduce confusion.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
{
int i, buflen;
char *last, **next, *s;
{
int i, buflen;
char *last, **next, *s;
+ struct env_entry *match, search;
static char *var;
last = (char *)va_arg(ap, unsigned long);
static char *var;
last = (char *)va_arg(ap, unsigned long);
ssize_t len;
if (name) { /* print a single name */
ssize_t len;
if (name) { /* print a single name */
+ struct env_entry e, *ep;
e.key = name;
e.data = NULL;
e.key = name;
e.data = NULL;
{
int i, len;
char *name, *value, *s;
{
int i, len;
char *name, *value, *s;
+ struct env_entry e, *ep;
debug("Initial value for argc=%d\n", argc);
debug("Initial value for argc=%d\n", argc);
-static int print_active_callback(ENTRY *entry)
+static int print_active_callback(struct env_entry *entry)
{
struct env_clbk_tbl *clbkp;
int i;
{
struct env_clbk_tbl *clbkp;
int i;
-static int print_active_flags(ENTRY *entry)
+static int print_active_flags(struct env_entry *entry)
{
enum env_flags_vartype type;
enum env_flags_varaccess access;
{
enum env_flags_vartype type;
enum env_flags_varaccess access;
char *env_get(const char *name)
{
if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
char *env_get(const char *name)
{
if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
+ struct env_entry e, *ep;
static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct env_entry e, *ep;
if (argc < 2)
return CMD_RET_USAGE;
if (argc < 2)
return CMD_RET_USAGE;
struct tee_param *params)
{
struct sandbox_tee_state *state = dev_get_priv(dev);
struct tee_param *params)
{
struct sandbox_tee_state *state = dev_get_priv(dev);
+ struct env_entry e, *ep;
char *name;
u32 res;
uint slot;
char *name;
u32 res;
uint slot;
* This is called specifically when the variable did not exist in the hash
* previously, so the blanket update did not find this variable.
*/
* This is called specifically when the variable did not exist in the hash
* previously, so the blanket update did not find this variable.
*/
-void env_callback_init(ENTRY *var_entry)
+void env_callback_init(struct env_entry *var_entry)
{
const char *var_name = var_entry->key;
char callback_name[256] = "";
{
const char *var_name = var_entry->key;
char callback_name[256] = "";
* Called on each existing env var prior to the blanket update since removing
* a callback association should remove its callback.
*/
* Called on each existing env var prior to the blanket update since removing
* a callback association should remove its callback.
*/
-static int clear_callback(ENTRY *entry)
+static int clear_callback(struct env_entry *entry)
{
entry->callback = NULL;
{
entry->callback = NULL;
*/
static int set_callback(const char *name, const char *value, void *priv)
{
*/
static int set_callback(const char *name, const char *value, void *priv)
{
+ struct env_entry e, *ep;
struct env_clbk_tbl *clbkp;
e.key = name;
struct env_clbk_tbl *clbkp;
e.key = name;
int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf,
bool dollar_comp)
{
int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf,
bool dollar_comp)
{
+ struct env_entry *match;
int found, idx;
if (dollar_comp) {
int found, idx;
if (dollar_comp) {
* This is called specifically when the variable did not exist in the hash
* previously, so the blanket update did not find this variable.
*/
* This is called specifically when the variable did not exist in the hash
* previously, so the blanket update did not find this variable.
*/
-void env_flags_init(ENTRY *var_entry)
+void env_flags_init(struct env_entry *var_entry)
{
const char *var_name = var_entry->key;
char flags[ENV_FLAGS_ATTR_MAX_LEN + 1] = "";
{
const char *var_name = var_entry->key;
char flags[ENV_FLAGS_ATTR_MAX_LEN + 1] = "";
* Called on each existing env var prior to the blanket update since removing
* a flag in the flag list should remove its flags.
*/
* Called on each existing env var prior to the blanket update since removing
* a flag in the flag list should remove its flags.
*/
-static int clear_flags(ENTRY *entry)
+static int clear_flags(struct env_entry *entry)
*/
static int set_flags(const char *name, const char *value, void *priv)
{
*/
static int set_flags(const char *name, const char *value, void *priv)
{
+ struct env_entry e, *ep;
e.key = name;
e.data = NULL;
e.key = name;
e.data = NULL;
* overwriting of write-once variables.
*/
* overwriting of write-once variables.
*/
-int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
- int flag)
+int env_flags_validate(const struct env_entry *item, const char *newval,
+ enum env_op op, int flag)
{
const char *name;
const char *oldval = NULL;
{
const char *name;
const char *oldval = NULL;
"serial#:serialno," \
CONFIG_ENV_CALLBACK_LIST_STATIC
"serial#:serialno," \
CONFIG_ENV_CALLBACK_LIST_STATIC
-void env_callback_init(ENTRY *var_entry);
+void env_callback_init(struct env_entry *var_entry);
#endif /* __ENV_CALLBACK_H__ */
#endif /* __ENV_CALLBACK_H__ */
* When adding a variable to the environment, initialize the flags for that
* variable.
*/
* When adding a variable to the environment, initialize the flags for that
* variable.
*/
-void env_flags_init(ENTRY *var_entry);
+void env_flags_init(struct env_entry *var_entry);
/*
* Validate the newval for to conform with the requirements defined by its flags
*/
/*
* Validate the newval for to conform with the requirements defined by its flags
*/
-int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
- int flag);
+int env_flags_validate(const struct env_entry *item, const char *newval,
+ enum env_op op, int flag);
+/** struct env_entry - An entry in the environment hashtable */
+struct env_entry {
const char *key;
char *data;
int (*callback)(const char *name, const char *value, enum env_op op,
int flags);
int flags;
const char *key;
char *data;
int (*callback)(const char *name, const char *value, enum env_op op,
int flags);
int flags;
/* Opaque type for internal use. */
struct _ENTRY;
/* Opaque type for internal use. */
struct _ENTRY;
* shall force overwriting of write-once variables.
* Must return 0 for approval, 1 for denial.
*/
* shall force overwriting of write-once variables.
* Must return 0 for approval, 1 for denial.
*/
- int (*change_ok)(const ENTRY *__item, const char *newval, enum env_op,
- int flag);
+ int (*change_ok)(const struct env_entry *__item, const char *newval,
+ enum env_op, int flag);
};
/* Create a new hash table which will contain at most "__nel" elements. */
};
/* Create a new hash table which will contain at most "__nel" elements. */
* NULL. If ACTION is `ENTER' replace existing data (if any) with
* __item.data.
* */
* NULL. If ACTION is `ENTER' replace existing data (if any) with
* __item.data.
* */
-extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
- struct hsearch_data *__htab, int __flag);
+extern int hsearch_r(struct env_entry __item, ACTION __action,
+ struct env_entry **__retval, struct hsearch_data *__htab,
+ int __flag);
/*
* Search for an entry matching "__match". Otherwise, Same semantics
* as hsearch_r().
*/
/*
* Search for an entry matching "__match". Otherwise, Same semantics
* as hsearch_r().
*/
-extern int hmatch_r(const char *__match, int __last_idx, ENTRY ** __retval,
- struct hsearch_data *__htab);
+extern int hmatch_r(const char *__match, int __last_idx,
+ struct env_entry **__retval, struct hsearch_data *__htab);
/* Search and delete entry matching "__key" in internal hash table. */
extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
/* Search and delete entry matching "__key" in internal hash table. */
extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
char * const vars[]);
/* Walk the whole table calling the callback on each element */
char * const vars[]);
/* Walk the whole table calling the callback on each element */
-extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));
+extern int hwalk_r(struct hsearch_data *__htab,
+ int (*callback)(struct env_entry *entry));
/* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
#define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */
/* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
#define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */
typedef struct _ENTRY {
int used;
typedef struct _ENTRY {
int used;
+ struct env_entry entry;
-static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
- int idx);
+static void _hdelete(const char *key, struct hsearch_data *htab,
+ struct env_entry *ep, int idx);
/* free used memory */
for (i = 1; i <= htab->size; ++i) {
if (htab->table[i].used > 0) {
/* free used memory */
for (i = 1; i <= htab->size; ++i) {
if (htab->table[i].used > 0) {
- ENTRY *ep = &htab->table[i].entry;
+ struct env_entry *ep = &htab->table[i].entry;
free((void *)ep->key);
free(ep->data);
free((void *)ep->key);
free(ep->data);
* example for functions like hdelete().
*/
* example for functions like hdelete().
*/
-int hmatch_r(const char *match, int last_idx, ENTRY ** retval,
+int hmatch_r(const char *match, int last_idx, struct env_entry **retval,
struct hsearch_data *htab)
{
unsigned int idx;
struct hsearch_data *htab)
{
unsigned int idx;
* Compare an existing entry with the desired key, and overwrite if the action
* is ENTER. This is simply a helper function for hsearch_r().
*/
* Compare an existing entry with the desired key, and overwrite if the action
* is ENTER. This is simply a helper function for hsearch_r().
*/
-static inline int _compare_and_overwrite_entry(ENTRY item, ACTION action,
- ENTRY **retval, struct hsearch_data *htab, int flag,
- unsigned int hval, unsigned int idx)
+static inline int _compare_and_overwrite_entry(struct env_entry item,
+ ACTION action, struct env_entry **retval,
+ struct hsearch_data *htab, int flag, unsigned int hval,
+ unsigned int idx)
{
if (htab->table[idx].used == hval
&& strcmp(item.key, htab->table[idx].entry.key) == 0) {
{
if (htab->table[idx].used == hval
&& strcmp(item.key, htab->table[idx].entry.key) == 0) {
-int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
+int hsearch_r(struct env_entry item, ACTION action, struct env_entry **retval,
struct hsearch_data *htab, int flag)
{
unsigned int hval;
struct hsearch_data *htab, int flag)
{
unsigned int hval;
-static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
- int idx)
+static void _hdelete(const char *key, struct hsearch_data *htab,
+ struct env_entry *ep, int idx)
debug("hdelete: DELETING key \"%s\"\n", key);
free((void *)ep->key);
free(ep->data);
debug("hdelete: DELETING key \"%s\"\n", key);
free((void *)ep->key);
free(ep->data);
int hdelete_r(const char *key, struct hsearch_data *htab, int flag)
{
int hdelete_r(const char *key, struct hsearch_data *htab, int flag)
{
+ struct env_entry e, *ep;
int idx;
debug("hdelete: DELETE key \"%s\"\n", key);
int idx;
debug("hdelete: DELETE key \"%s\"\n", key);
static int cmpkey(const void *p1, const void *p2)
{
static int cmpkey(const void *p1, const void *p2)
{
- ENTRY *e1 = *(ENTRY **) p1;
- ENTRY *e2 = *(ENTRY **) p2;
+ struct env_entry *e1 = *(struct env_entry **)p1;
+ struct env_entry *e2 = *(struct env_entry **)p2;
return (strcmp(e1->key, e2->key));
}
return (strcmp(e1->key, e2->key));
}
-static int match_entry(ENTRY *ep, int flag,
- int argc, char * const argv[])
+static int match_entry(struct env_entry *ep, int flag, int argc,
+ char *const argv[])
{
int arg;
void *priv = NULL;
{
int arg;
void *priv = NULL;
char **resp, size_t size,
int argc, char * const argv[])
{
char **resp, size_t size,
int argc, char * const argv[])
{
- ENTRY *list[htab->size];
+ struct env_entry *list[htab->size];
char *res, *p;
size_t totlen;
int i, n;
char *res, *p;
size_t totlen;
int i, n;
for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {
if (htab->table[i].used > 0) {
for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {
if (htab->table[i].used > 0) {
- ENTRY *ep = &htab->table[i].entry;
+ struct env_entry *ep = &htab->table[i].entry;
int found = match_entry(ep, flag, argc, argv);
if ((argc > 0) && (found == 0))
int found = match_entry(ep, flag, argc, argv);
if ((argc > 0) && (found == 0))
#endif
/* Sort list by keys */
#endif
/* Sort list by keys */
- qsort(list, n, sizeof(ENTRY *), cmpkey);
+ qsort(list, n, sizeof(struct env_entry *), cmpkey);
/* Check if the user supplied buffer size is sufficient */
if (size) {
/* Check if the user supplied buffer size is sufficient */
if (size) {
}
/* Parse environment; allow for '\0' and 'sep' as separators */
do {
}
/* Parse environment; allow for '\0' and 'sep' as separators */
do {
+ struct env_entry e, *rv;
/* skip leading white space */
while (isblank(*dp))
/* skip leading white space */
while (isblank(*dp))
* Walk all of the entries in the hash, calling the callback for each one.
* this allows some generic operation to be performed on each element.
*/
* Walk all of the entries in the hash, calling the callback for each one.
* this allows some generic operation to be performed on each element.
*/
-int hwalk_r(struct hsearch_data *htab, int (*callback)(ENTRY *))
+int hwalk_r(struct hsearch_data *htab, int (*callback)(struct env_entry *entry))
struct hsearch_data *htab, size_t size)
{
size_t i;
struct hsearch_data *htab, size_t size)
{
size_t i;
- ENTRY item;
- ENTRY *ritem;
+ struct env_entry item;
+ struct env_entry *ritem;
char key[20];
for (i = 0; i < size; i++) {
char key[20];
for (i = 0; i < size; i++) {
struct hsearch_data *htab, size_t size)
{
size_t i;
struct hsearch_data *htab, size_t size)
{
size_t i;
- ENTRY item;
- ENTRY *ritem;
+ struct env_entry item;
+ struct env_entry *ritem;
char key[20];
for (i = 0; i < size; i++) {
char key[20];
for (i = 0; i < size; i++) {
struct hsearch_data *htab, size_t iterations)
{
size_t i;
struct hsearch_data *htab, size_t iterations)
{
size_t i;
- ENTRY item;
- ENTRY *ritem;
+ struct env_entry item;
+ struct env_entry *ritem;
char key[20];
for (i = 0; i < iterations; i++) {
char key[20];
for (i = 0; i < iterations; i++) {