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

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