Blame SOURCES/0009-Trim-whitespaces-when-reading-configuration.patch

d7fdbd
From d024bc27cee40f21e6a3841266062408c44e56fb Mon Sep 17 00:00:00 2001
d7fdbd
From: Martin Sehnoutka <msehnout@redhat.com>
d7fdbd
Date: Wed, 7 Sep 2016 10:35:54 +0200
d7fdbd
Subject: [PATCH 09/59] Trim whitespaces when reading configuration.
d7fdbd
d7fdbd
---
d7fdbd
 parseconf.c |  2 +-
d7fdbd
 str.c       | 12 ++++++++++++
d7fdbd
 str.h       |  1 +
d7fdbd
 sysutil.c   | 12 ++++++++++++
d7fdbd
 sysutil.h   |  1 +
d7fdbd
 5 files changed, 27 insertions(+), 1 deletion(-)
d7fdbd
d7fdbd
diff --git a/parseconf.c b/parseconf.c
d7fdbd
index 385afd2..30df598 100644
d7fdbd
--- a/parseconf.c
d7fdbd
+++ b/parseconf.c
d7fdbd
@@ -280,7 +280,7 @@ vsf_parseconf_load_setting(const char* p_setting, int errs_fatal)
d7fdbd
         }
d7fdbd
         else
d7fdbd
         {
d7fdbd
-          *p_curr_setting = str_strdup(&s_value_str);
d7fdbd
+          *p_curr_setting = str_strdup_trimmed(&s_value_str);
d7fdbd
         }
d7fdbd
         return;
d7fdbd
       }
d7fdbd
diff --git a/str.c b/str.c
d7fdbd
index ba4b92a..41b27db 100644
d7fdbd
--- a/str.c
d7fdbd
+++ b/str.c
d7fdbd
@@ -104,6 +104,18 @@ str_strdup(const struct mystr* p_str)
d7fdbd
   return vsf_sysutil_strdup(str_getbuf(p_str));
d7fdbd
 }
d7fdbd
 
d7fdbd
+const char*
d7fdbd
+str_strdup_trimmed(const struct mystr* p_str)
d7fdbd
+{
d7fdbd
+  const char* p_trimmed = str_getbuf(p_str);
d7fdbd
+  int h, t, newlen;
d7fdbd
+
d7fdbd
+  for (h = 0; h < (int)str_getlen(p_str) && vsf_sysutil_isspace(p_trimmed[h]); h++) ;
d7fdbd
+  for (t = str_getlen(p_str) - 1; t >= 0 && vsf_sysutil_isspace(p_trimmed[t]); t--) ;
d7fdbd
+  newlen = t - h + 1;
d7fdbd
+  return newlen ? vsf_sysutil_strndup(p_trimmed+h, (unsigned int)newlen) : 0L;
d7fdbd
+}
d7fdbd
+
d7fdbd
 void
d7fdbd
 str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term)
d7fdbd
 {
d7fdbd
diff --git a/str.h b/str.h
d7fdbd
index 3a21b50..44270da 100644
d7fdbd
--- a/str.h
d7fdbd
+++ b/str.h
d7fdbd
@@ -31,6 +31,7 @@ void str_alloc_ulong(struct mystr* p_str, unsigned long the_ulong);
d7fdbd
 void str_alloc_filesize_t(struct mystr* p_str, filesize_t the_filesize);
d7fdbd
 void str_copy(struct mystr* p_dest, const struct mystr* p_src);
d7fdbd
 const char* str_strdup(const struct mystr* p_str);
d7fdbd
+const char* str_strdup_trimmed(const struct mystr* p_str);
d7fdbd
 void str_empty(struct mystr* p_str);
d7fdbd
 void str_free(struct mystr* p_str);
d7fdbd
 void str_trunc(struct mystr* p_str, unsigned int trunc_len);
d7fdbd
diff --git a/sysutil.c b/sysutil.c
d7fdbd
index 5cdb6ef..428a34a 100644
d7fdbd
--- a/sysutil.c
d7fdbd
+++ b/sysutil.c
d7fdbd
@@ -1035,6 +1035,18 @@ vsf_sysutil_strdup(const char* p_str)
d7fdbd
   return strdup(p_str);
d7fdbd
 }
d7fdbd
 
d7fdbd
+char*
d7fdbd
+vsf_sysutil_strndup(const char* p_str, unsigned int p_len)
d7fdbd
+{
d7fdbd
+  char *new = (char *)malloc(p_len+1);
d7fdbd
+
d7fdbd
+  if (new == NULL)
d7fdbd
+    return NULL;
d7fdbd
+
d7fdbd
+  new[p_len]='\0';
d7fdbd
+  return (char *)memcpy(new, p_str, p_len);
d7fdbd
+}
d7fdbd
+
d7fdbd
 void
d7fdbd
 vsf_sysutil_memclr(void* p_dest, unsigned int size)
d7fdbd
 {
d7fdbd
diff --git a/sysutil.h b/sysutil.h
d7fdbd
index c34778c..c2ddd15 100644
d7fdbd
--- a/sysutil.h
d7fdbd
+++ b/sysutil.h
d7fdbd
@@ -186,6 +186,7 @@ int vsf_sysutil_wait_get_exitcode(
d7fdbd
 /* Various string functions */
d7fdbd
 unsigned int vsf_sysutil_strlen(const char* p_text);
d7fdbd
 char* vsf_sysutil_strdup(const char* p_str);
d7fdbd
+char* vsf_sysutil_strndup(const char* p_str, unsigned int p_len);
d7fdbd
 void vsf_sysutil_memclr(void* p_dest, unsigned int size);
d7fdbd
 void vsf_sysutil_memcpy(void* p_dest, const void* p_src,
d7fdbd
                         const unsigned int size);
d7fdbd
-- 
d7fdbd
2.14.4
d7fdbd