From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Fri, 24 Aug 2012 23:12:09 +0200 Subject: [U-Boot] [PATCH v4 7/7] env: delete selected vars not present in imported env In-Reply-To: <50379AD5.6030709@keymile.com> References: <1321634955-5561-1-git-send-email-gerlando.falauto@keymile.com> <201208241658.56669.marex@denx.de> <50379AD5.6030709@keymile.com> Message-ID: <201208242312.09462.marek.vasut@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Gerlando Falauto, > On 08/24/2012 04:58 PM, Marek Vasut wrote: > > Dear Gerlando Falauto, > > > >> When variables explicitly specified on the command line are not present > >> in the imported env, delete them from the running env. > >> If the variable is also missing from the running env, issue a warning. > >> > >> Signed-off-by: Gerlando Falauto > > > > Whew! I made it through ... it wasn't that scary in the end ;-) > > > >> --- > >> > >> lib/hashtable.c | 48 > >> +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 > >> insertions(+), 7 deletions(-) > >> > >> diff --git a/lib/hashtable.c b/lib/hashtable.c > >> index f3f47de..b3d0b64 100644 > >> --- a/lib/hashtable.c > >> +++ b/lib/hashtable.c > >> @@ -607,22 +607,32 @@ 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[]) +/* > >> + * Check whether variable 'name' is amongst vars[], > >> + * and remove all instances by setting the pointer to NULL > >> + */ > >> +static int is_var_in_set(const char *name, int nvars, char * vars[]) > >> > >> { > >> > >> int i = 0; > >> > >> + int res = 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; > >> + if (vars[i] == NULL) > >> + continue; > >> + /* If we found it, delete all of them */ > >> + if (!strcmp(name, vars[i])) { > >> + vars[i] = NULL; > >> + res = 1; > > > > break here ? > > Nope, if we find it, we should delete all of them (see comment above). Stupid me, of course now I see the logic! Sorry! > >> + } > >> > >> } > >> > >> - debug("Skipping non-listed variable %s\n", name); > >> + if (!res) > >> + debug("Skipping non-listed variable %s\n", name); > >> > >> - return 0; > >> + return res; > >> > >> } > >> > >> /* > >> > >> @@ -662,9 +672,11 @@ 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 do_apply) > >> + int nvars, char * const __vars[], int do_apply) > > > > Two underscores are reserved, use something else ;-) > > Like... one? three? ;-) I think one is the way to go ... http://lwn.net/Articles/509149/ definitelly not like this ;-) [...] Best regards, Marek Vasut