[dm-devel] [PATCH v2 04/21] libmultipath: strbuf: add __get_strbuf_buf()
mwilck at suse.com
mwilck at suse.com
Wed Dec 1 12:36:33 UTC 2021
From: Martin Wilck <mwilck at suse.com>
Add a function for internal use that allows direct manipulation
of the strbuf's content.
Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
libmultipath/strbuf.c | 5 +++++
libmultipath/strbuf.h | 14 ++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/libmultipath/strbuf.c b/libmultipath/strbuf.c
index a24a57d..f654594 100644
--- a/libmultipath/strbuf.c
+++ b/libmultipath/strbuf.c
@@ -15,6 +15,11 @@
static const char empty_str[] = "";
+char *__get_strbuf_buf(struct strbuf *buf)
+{
+ return buf->buf;
+}
+
const char *get_strbuf_str(const struct strbuf *buf)
{
return buf->buf ? buf->buf : empty_str;
diff --git a/libmultipath/strbuf.h b/libmultipath/strbuf.h
index 5903572..41d7d54 100644
--- a/libmultipath/strbuf.h
+++ b/libmultipath/strbuf.h
@@ -54,6 +54,20 @@ void free_strbuf(struct strbuf *buf);
*/
struct strbuf *new_strbuf(void);
+/**
+ * get_strbuf_buf(): retrieve a pointer to the strbuf's buffer
+ * @param buf: a struct strbuf
+ * @returns: pointer to the string written to the strbuf so far.
+ *
+ * INTERNAL ONLY.
+ * DANGEROUS: Unlike the return value of get_strbuf_str(),
+ * this string can be written to, modifying the strbuf's content.
+ * USE WITH CAUTION.
+ * If @strbuf was never written to, the function returns NULL.
+ * The return value of this function must not be free()d.
+ */
+char *__get_strbuf_buf(struct strbuf *buf);
+
/**
* get_strbuf_str(): retrieve string from strbuf
* @param buf: a struct strbuf
--
2.33.1
More information about the dm-devel
mailing list