Add an API to convert a dynamic string object into ofpbuf.
Signed-off-by: Andy Zhou <[email protected]>
---
lib/ofpbuf.c | 10 ++++++++++
lib/ofpbuf.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c
index 9b9d6b2..392f843 100644
--- a/lib/ofpbuf.c
+++ b/lib/ofpbuf.c
@@ -53,6 +53,16 @@ ofpbuf_use(struct ofpbuf *b, void *base, size_t allocated)
ofpbuf_use__(b, base, allocated, 0, OFPBUF_MALLOC);
}
+/* Converts ds into ofpbuf 'b'. 'b' contains the 'ds->allocated' bytes of
+ * memory starting at 'ds->string'. 'ds' should not be modified any more.
+ * The memory allocated for 'ds' will be freed (with free()) if 'b' is
+ * resized or freed. */
+void
+ofpbuf_use_ds(struct ofpbuf *b, const struct ds *ds)
+{
+ ofpbuf_use__(b, ds->string, ds->allocated + 1, ds->length, OFPBUF_MALLOC);
+}
+
/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
* memory starting at 'base'. 'base' should point to a buffer on the stack.
* (Nothing actually relies on 'base' being allocated on the stack. It could
diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h
index 9e82de2..17257a0 100644
--- a/lib/ofpbuf.h
+++ b/lib/ofpbuf.h
@@ -84,6 +84,7 @@ struct ofpbuf {
}
void ofpbuf_use(struct ofpbuf *, void *, size_t);
+void ofpbuf_use_ds(struct ofpbuf *, const struct ds *);
void ofpbuf_use_stack(struct ofpbuf *, void *, size_t);
void ofpbuf_use_stub(struct ofpbuf *, void *, size_t);
void ofpbuf_use_const(struct ofpbuf *, const void *, size_t);
--
1.9.1
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev