public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexander Holler <holler@ahsoftware.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Ignore all Carriage Returns when importing an environment.
Date: Fri, 11 May 2012 09:14:46 +0200	[thread overview]
Message-ID: <1336720486-7424-1-git-send-email-holler@ahsoftware.de> (raw)

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@ahsoftware.de>
---
 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;
-- 
1.7.3.4

             reply	other threads:[~2012-05-11  7:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11  7:14 Alexander Holler [this message]
2012-05-11 19:09 ` [U-Boot] [PATCH] Ignore all Carriage Returns when importing an environment Wolfgang Denk
2012-05-12 14:22   ` Alexander Holler
2012-05-12 21:18     ` Wolfgang Denk
2012-05-13  8:07       ` Alexander Holler
2012-05-13  9:27         ` Wolfgang Denk
2012-05-12  6:17 ` Marek Vasut
2012-05-12 14:25   ` Alexander Holler
2012-05-12 14:46     ` Marek Vasut
2012-05-12 14:50       ` Alexander Holler
2012-05-12 16:08         ` Marek Vasut
2012-05-12 18:33           ` Alexander Holler
2012-05-12 18:37             ` Marek Vasut
2012-05-12 19:10               ` Alexander Holler
2012-05-12 21:21                 ` Wolfgang Denk
2012-05-13  7:43                   ` Alexander Holler
2012-05-12 21:19         ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336720486-7424-1-git-send-email-holler@ahsoftware.de \
    --to=holler@ahsoftware.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox