You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
1.7 KiB

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