]> git.sur5r.net Git - u-boot/blobdiff - lib/hashtable.c
env: add check/apply logic to himport_r()
[u-boot] / lib / hashtable.c
index 0610e867d08b5f9f8b55e2352068c2b8ff86c5a0..6cfba5668265e302fc950754f7b7d05fce28c768 100644 (file)
@@ -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",