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

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