[U-Boot] [PATCH] Ignore all Carriage Returns when importing an environment.

Marek Vasut marex at denx.de
Sat May 12 16:46:09 CEST 2012


Dear Alexander Holler,

> Am 12.05.2012 08:17, schrieb Marek Vasut:
> > Dear Alexander Holler,
> > 
> >> This is used for compatibility with text files which are
> >> using CRLF instead of LF as the end of a line.
> >> 
> >> Signed-off-by: Alexander Holler<holler at ahsoftware.de>
> > 
> > Why don't you run the file trough dos2unix or tr -d '\r' ?
> 
> Because my files don't contain CRs. ;)

s/you/someone else/ :)

> 
> Regards,
> 
> Alexander
> 
> >> ---
> >> 
> >>   lib/hashtable.c |   18 +++++++++++++++---
> >>   1 files changed, 15 insertions(+), 3 deletions(-)
> >> 
> >> diff --git a/lib/hashtable.c b/lib/hashtable.c
> >> index abd61c8..6e146ce 100644
> >> --- a/lib/hashtable.c
> >> +++ b/lib/hashtable.c
> >> @@ -623,9 +623,9 @@ ssize_t hexport_r(struct hsearch_data *htab, const
> >> char sep, * (entries separated by newline characters).
> >> 
> >>    *
> >>    * To allow for nicely formatted text input, leading white space
> >> 
> >> - * (sequences of SPACE and TAB chars) is ignored, and entries starting
> >> - * (after removal of any leading white space) with a '#' character are
> >> - * considered comments and ignored.
> >> + * (sequences of SPACE and TAB chars) is ignored, all Carriage Returns
> >> + * are ignored and entries starting (after removal of any leading white
> >> + * space) with a '#' character are considered comments and ignored.
> >> 
> >>    *
> >>    * [NOTE: this means that a variable name cannot start with a '#'
> >>    * character.]
> >> 
> >> @@ -642,6 +642,7 @@ int himport_r(struct hsearch_data *htab,
> >> 
> >>   	      const char *env, size_t size, const char sep, int flag)
> >>   
> >>   {
> >>   
> >>   	char *data, *sp, *dp, *name, *value;
> >> 
> >> +	unsigned ignored_crs;
> >> 
> >>   	/* Test for correct arguments.  */
> >>   	if (htab == NULL) {
> >> 
> >> @@ -698,6 +699,17 @@ int himport_r(struct hsearch_data *htab,
> >> 
> >>   		}
> >>   	
> >>   	}
> >> 
> >> +	/* Remove all Carriage Returns */
> >> +	ignored_crs = 0;
> >> +	for(;dp<  data + size&&  *dp; ++dp) {
> >> +		if( *dp == '\r' )
> >> +			++ignored_crs;
> >> +		else if(ignored_crs)
> >> +			*(dp-ignored_crs) = *dp;
> >> +	}
> >> +	size -= ignored_crs;
> >> +	dp = data;
> >> +
> >> 
> >>   	/* Parse environment; allow for '\0' and 'sep' as separators */
> >>   	do {
> >>   	
> >>   		ENTRY e, *rv;
> > 
> > Best regards,
> > Marek Vasut
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


More information about the U-Boot mailing list