/* Delete only ? */
if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, &env_htab, env_flag);
- return !rc;
+
+ /* If the variable didn't exist, don't report an error */
+ return rc && rc != -ENOENT ? 1 : 0;
}
/*
while (--argc > 0) {
char *name = *++argv;
- if (!hdelete_r(name, &env_htab, env_flag))
+ if (hdelete_r(name, &env_htab, env_flag))
ret = 1;
}
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. */
+/**
+ * hdelete_r() - Search and delete entry in internal hash table
+ *
+ * @key: Name of entry to delete
+ * @htab: Hash table
+ * @flag: Flags to use (H_...)
+ * @return 0 on success, -ENOENT if not found, -EPERM if the hash table callback
+ * rejected changing the variable, -EINVAL if the hash table refused to
+ * delete the variable
+ */
int hdelete_r(const char *key, struct hsearch_data *htab, int flag);
ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
idx = hsearch_r(e, ENV_FIND, &ep, htab, 0);
if (idx == 0) {
__set_errno(ESRCH);
- return 0; /* not found */
+ return -ENOENT; /* not found */
}
/* Check for permission */
debug("change_ok() rejected deleting variable "
"%s, skipping it!\n", key);
__set_errno(EPERM);
- return 0;
+ return -EPERM;
}
/* If there is a callback, call it */
debug("callback() rejected deleting variable "
"%s, skipping it!\n", key);
__set_errno(EINVAL);
- return 0;
+ return -EINVAL;
}
_hdelete(key, htab, ep, idx);
- return 1;
+ return 0;
}
#if !(defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_SAVEENV))
if (!drop_var_from_set(name, nvars, localvars))
continue;
- if (hdelete_r(name, htab, flag) == 0)
+ if (hdelete_r(name, htab, flag))
debug("DELETE ERROR ##############################\n");
continue;
* b) if the variable was not present in current env, we notify
* it might be a typo
*/
- if (hdelete_r(localvars[i], htab, flag) == 0)
+ if (hdelete_r(localvars[i], htab, flag))
printf("WARNING: '%s' neither in running nor in imported env!\n", localvars[i]);
else
printf("WARNING: '%s' not in imported env, deleting it!\n", localvars[i]);
ut_asserteq_str(key, ritem->key);
ut_asserteq_str(key, ritem->data);
- ut_asserteq(1, hdelete_r(key, htab, 0));
+ ut_asserteq(0, hdelete_r(key, htab, 0));
}
return 0;