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