summaryrefslogtreecommitdiff
path: root/lib/hashtable.c
diff options
context:
space:
mode:
authorGerlando Falauto <gerlando.falauto@keymile.com>2012-08-24 00:11:39 +0000
committerTom Rini <trini@ti.com>2012-09-18 12:01:52 -0700
commitc5983592e912835fe9ed00b9d98b05580c460eae (patch)
tree96245807698607969286b6b4d0b2f1b664fdb3e8 /lib/hashtable.c
parent348b1f1c6064990210a6797c86514fd358b73062 (diff)
downloadu-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.zip
u-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.tar.gz
u-boot-imx-c5983592e912835fe9ed00b9d98b05580c460eae.tar.bz2
env: add check/apply logic to himport_r()
Change hashtable so that a callback function will decide whether a variable can be overwritten, and possibly apply the changes. So add a new field to struct hsearch_data: o "apply" callback function to check whether a variable can be overwritten, and possibly immediately apply the changes; when NULL, no check is performed. And a new argument to himport_r(): o "do_apply": whether to call the apply callback function NOTE: This patch does not change the current behavior. Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com> Reviewed-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'lib/hashtable.c')
-rw-r--r--lib/hashtable.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 0610e86..6cfba56 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -658,7 +658,7 @@ static int is_var_in_set(const char *name, int nvars, char * const vars[])
int himport_r(struct hsearch_data *htab,
const char *env, size_t size, const char sep, int flag,
- int nvars, char * const vars[])
+ int nvars, char * const vars[], int do_apply)
{
char *data, *sp, *dp, *name, *value;
@@ -772,6 +772,24 @@ int himport_r(struct hsearch_data *htab,
e.key = name;
e.data = value;
+ /* if there is an apply function, check what it has to say */
+ if (do_apply && htab->apply != NULL) {
+ debug("searching before calling cb function"
+ " for %s\n", name);
+ /*
+ * Search for variable in existing env, so to pass
+ * its previous value to the apply callback
+ */
+ hsearch_r(e, FIND, &rv, htab);
+ debug("previous value was %s\n", rv ? rv->data : "");
+ if (htab->apply(name, rv ? rv->data : NULL,
+ value, flag)) {
+ debug("callback function refused to set"
+ " variable %s, skipping it!\n", name);
+ continue;
+ }
+ }
+
hsearch_r(e, ENTER, &rv, htab);
if (rv == NULL) {
printf("himport_r: can't insert \"%s=%s\" into hash table\n",