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

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