if (s != NULL)
*s = 0;
search.key = var;
- i = hsearch_r(search, FIND, &match, &env_htab, 0);
+ i = hsearch_r(search, ENV_FIND, &match, &env_htab, 0);
if (i == 0) {
i = API_EINVAL;
goto done;
e.key = name;
e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, flag);
+ hsearch_r(e, ENV_FIND, &ep, &env_htab, flag);
if (ep == NULL)
return 0;
len = printf("%s=%s\n", ep->key, ep->data);
e.key = name;
e.data = value;
- hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
+ hsearch_r(e, ENV_ENTER, &ep, &env_htab, env_flag);
free(value);
if (!ep) {
printf("## Error inserting \"%s\" variable, errno=%d\n",
e.key = name;
e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
return ep ? ep->data : NULL;
}
e.key = argv[1];
e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
return (ep == NULL) ? 1 : 0;
}
e.key = name;
e.data = NULL;
- hsearch_r(e, FIND, &ep, &state->pstorage_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &state->pstorage_htab, 0);
if (!ep)
return TEE_ERROR_ITEM_NOT_FOUND;
e.key = name;
e.data = NULL;
- hsearch_r(e, FIND, &ep, &state->pstorage_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &state->pstorage_htab, 0);
if (ep)
hdelete_r(e.key, &state->pstorage_htab, 0);
e.key = name;
e.data = value;
- hsearch_r(e, ENTER, &ep, &state->pstorage_htab, 0);
+ hsearch_r(e, ENV_ENTER, &ep, &state->pstorage_htab, 0);
if (!ep)
return TEE_ERROR_OUT_OF_MEMORY;
e.key = name;
e.data = NULL;
e.callback = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
/* does the env variable actually exist? */
if (ep != NULL) {
e.key = name;
e.data = NULL;
e.callback = NULL;
- hsearch_r(e, FIND, &ep, &env_htab, 0);
+ hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
/* does the env variable actually exist? */
if (ep != NULL) {
#define __set_errno(val) do { errno = val; } while (0)
-/* Action which shall be performed in the call to hsearch. */
-typedef enum {
- FIND,
- ENTER
-} ACTION;
+/* enum env_action: action which shall be performed in the call to hsearch */
+enum env_action {
+ ENV_FIND,
+ ENV_ENTER,
+};
/** struct env_entry - An entry in the environment hashtable */
struct env_entry {
/*
* Search for entry matching __item.key in internal hash table. If
- * ACTION is `FIND' return found entry or signal error by returning
- * NULL. If ACTION is `ENTER' replace existing data (if any) with
+ * __action is `ENV_FIND' return found entry or signal error by returning
+ * NULL. If __action is `ENV_ENTER' replace existing data (if any) with
* __item.data.
* */
-extern int hsearch_r(struct env_entry __item, ACTION __action,
+extern int hsearch_r(struct env_entry __item, enum env_action __action,
struct env_entry **__retval, struct hsearch_data *__htab,
int __flag);
* data any more.
* - The standard implementation does not provide a way to update an
* existing entry. This version will create a new entry or update an
- * existing one when both "action == ENTER" and "item.data != NULL".
+ * existing one when both "action == ENV_ENTER" and "item.data != NULL".
* - Instead of returning 1 on success, we return the index into the
* internal hash table, which is also guaranteed to be positive.
* This allows us direct access to the found hash table slot for
/*
* Compare an existing entry with the desired key, and overwrite if the action
- * is ENTER. This is simply a helper function for hsearch_r().
+ * is ENV_ENTER. This is simply a helper function for hsearch_r().
*/
static inline int _compare_and_overwrite_entry(struct env_entry item,
- ACTION action, struct env_entry **retval,
+ enum env_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) {
/* Overwrite existing value? */
- if ((action == ENTER) && (item.data != NULL)) {
+ if (action == ENV_ENTER && item.data) {
/* check for permission */
if (htab->change_ok != NULL && htab->change_ok(
&htab->table[idx].entry, item.data,
return -1;
}
-int hsearch_r(struct env_entry item, ACTION action, struct env_entry **retval,
- struct hsearch_data *htab, int flag)
+int hsearch_r(struct env_entry item, enum env_action action,
+ struct env_entry **retval, struct hsearch_data *htab, int flag)
{
unsigned int hval;
unsigned int count;
}
/* An empty bucket has been found. */
- if (action == ENTER) {
+ if (action == ENV_ENTER) {
/*
* If table is full and another entry should be
* entered return with error.
e.key = (char *)key;
- idx = hsearch_r(e, FIND, &ep, htab, 0);
+ idx = hsearch_r(e, ENV_FIND, &ep, htab, 0);
if (idx == 0) {
__set_errno(ESRCH);
return 0; /* not found */
e.key = name;
e.data = value;
- hsearch_r(e, ENTER, &rv, htab, flag);
+ hsearch_r(e, ENV_ENTER, &rv, htab, flag);
if (rv == NULL)
printf("himport_r: can't insert \"%s=%s\" into hash table\n",
name, value);
item.data = key;
item.flags = 0;
item.key = key;
- ut_asserteq(1, hsearch_r(item, ENTER, &ritem, htab, 0));
+ ut_asserteq(1, hsearch_r(item, ENV_ENTER, &ritem, htab, 0));
}
return 0;
item.flags = 0;
item.data = key;
item.key = key;
- hsearch_r(item, FIND, &ritem, htab, 0);
+ hsearch_r(item, ENV_FIND, &ritem, htab, 0);
ut_assert(ritem);
ut_asserteq_str(key, ritem->key);
ut_asserteq_str(key, ritem->data);
item.flags = 0;
item.data = key;
item.key = key;
- hsearch_r(item, ENTER, &ritem, htab, 0);
+ hsearch_r(item, ENV_ENTER, &ritem, htab, 0);
ritem = NULL;
- hsearch_r(item, FIND, &ritem, htab, 0);
+ hsearch_r(item, ENV_FIND, &ritem, htab, 0);
ut_assert(ritem);
ut_asserteq_str(key, ritem->key);
ut_asserteq_str(key, ritem->data);