Blame SOURCES/0062-lib-add-xstrdup_between-str-open-close.patch

562801
From 952d080dfd832ecc3e5c31dde7c24077193aaec6 Mon Sep 17 00:00:00 2001
562801
From: Jakub Filak <jfilak@redhat.com>
562801
Date: Thu, 11 Sep 2014 12:29:49 +0200
562801
Subject: [LIBREPORT PATCH 62/93] lib: add xstrdup_between(str, open, close)
562801
562801
Related to rhbz#1140224
562801
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
---
562801
 src/include/internal_libreport.h |  2 ++
562801
 src/lib/xfuncs.c                 | 21 +++++++++++++++++++++
562801
 2 files changed, 23 insertions(+)
562801
562801
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
562801
index f9670b0..9ff89b2 100644
562801
--- a/src/include/internal_libreport.h
562801
+++ b/src/include/internal_libreport.h
562801
@@ -327,6 +327,8 @@ void* xzalloc(size_t size);
562801
 char* xstrdup(const char *s);
562801
 #define xstrndup libreport_xstrndup
562801
 char* xstrndup(const char *s, int n);
562801
+#define xstrdup_between libreport_xstrdup_between
562801
+char* xstrdup_between(const char *s, const char *open, const char *close);
562801
 
562801
 #define xpipe libreport_xpipe
562801
 void xpipe(int filedes[2]);
562801
diff --git a/src/lib/xfuncs.c b/src/lib/xfuncs.c
562801
index b5f04e2..1ce44aa 100644
562801
--- a/src/lib/xfuncs.c
562801
+++ b/src/lib/xfuncs.c
562801
@@ -107,6 +107,27 @@ char* xstrndup(const char *s, int n)
562801
     return (char*) memcpy(t, s, n);
562801
 }
562801
 
562801
+char *xstrdup_between(const char *src, const char *open, const char *close)
562801
+{
562801
+    const char *start = strstr(src, open);
562801
+    if (start == NULL)
562801
+    {
562801
+        log_debug("Open tag not found: '%s'", open);
562801
+        return NULL;
562801
+    }
562801
+
562801
+    start += strlen(open);
562801
+
562801
+    const char *stop = strstr(start, close);
562801
+    if (stop == NULL)
562801
+    {
562801
+        log_debug("Close tag not found: '%s'", close);
562801
+        return NULL;
562801
+    }
562801
+
562801
+    return xstrndup(start, stop - start);
562801
+}
562801
+
562801
 void xpipe(int filedes[2])
562801
 {
562801
     if (pipe(filedes))
562801
-- 
562801
1.8.3.1
562801