summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGerlando Falauto <gerlando.falauto@keymile.com>2012-08-24 00:11:38 +0000
committerTom Rini <trini@ti.com>2012-09-18 12:01:52 -0700
commit348b1f1c6064990210a6797c86514fd358b73062 (patch)
tree05d75464ef3a543a3c84a2fc7b2e2c3a61c029b3 /lib
parentc3f6525854bbc664ce9fbed9754af1daf56ba08e (diff)
downloadu-boot-imx-348b1f1c6064990210a6797c86514fd358b73062.zip
u-boot-imx-348b1f1c6064990210a6797c86514fd358b73062.tar.gz
u-boot-imx-348b1f1c6064990210a6797c86514fd358b73062.tar.bz2
env: make himport_r() selective on variables
Add 2 new arguments to himport_r(): o "nvars", "vars": number and list of variables to take into account (0 means ALL) NOTE: This patch does not change the current behaviour. Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com> Reviewed-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/hashtable.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c
index abd61c8..0610e86 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -603,6 +603,24 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
* himport()
*/
+/* Check whether variable name is amongst vars[] */
+static int is_var_in_set(const char *name, int nvars, char * const vars[])
+{
+ int i = 0;
+
+ /* No variables specified means process all of them */
+ if (nvars == 0)
+ return 1;
+
+ for (i = 0; i < nvars; i++) {
+ if (!strcmp(name, vars[i]))
+ return 1;
+ }
+ debug("Skipping non-listed variable %s\n", name);
+
+ return 0;
+}
+
/*
* Import linearized data into hash table.
*
@@ -639,7 +657,8 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
*/
int himport_r(struct hsearch_data *htab,
- const char *env, size_t size, const char sep, int flag)
+ const char *env, size_t size, const char sep, int flag,
+ int nvars, char * const vars[])
{
char *data, *sp, *dp, *name, *value;
@@ -726,6 +745,8 @@ int himport_r(struct hsearch_data *htab,
*dp++ = '\0'; /* terminate name */
debug("DELETE CANDIDATE: \"%s\"\n", name);
+ if (!is_var_in_set(name, nvars, vars))
+ continue;
if (hdelete_r(name, htab) == 0)
debug("DELETE ERROR ##############################\n");
@@ -743,6 +764,10 @@ int himport_r(struct hsearch_data *htab,
*sp++ = '\0'; /* terminate value */
++dp;
+ /* Skip variables which are not supposed to be processed */
+ if (!is_var_in_set(name, nvars, vars))
+ continue;
+
/* enter into hash table */
e.key = name;
e.data = value;