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

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