An upcoming commit will add the first user.
Signed-off-by: Ben Pfaff <[email protected]>
---
lib/ofpbuf.c | 18 ++++++++++++++++++
lib/ofpbuf.h | 1 +
2 files changed, 19 insertions(+)
diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c
index d578ab5..27b6f17 100644
--- a/lib/ofpbuf.c
+++ b/lib/ofpbuf.c
@@ -359,6 +359,24 @@ ofpbuf_padto(struct ofpbuf *b, size_t length)
}
}
+/* Shifts all of the data within the allocated space in 'b' by 'delta' bytes.
+ * For example, a 'delta' of 1 would cause each byte of data to move one byte
+ * forward (from address 'p' to 'p+1'), and a 'delta' of -1 would cause each
+ * byte to move one byte backward (from 'p' to 'p-1'). */
+void
+ofpbuf_shift(struct ofpbuf *b, int delta)
+{
+ ovs_assert(delta > 0 ? delta <= ofpbuf_tailroom(b)
+ : delta < 0 ? -delta <= ofpbuf_headroom(b)
+ : true);
+
+ if (delta != 0) {
+ char *dst = (char *) b->data + delta;
+ memmove(dst, b->data, b->size);
+ b->data = dst;
+ }
+}
+
/* Appends 'size' bytes of data to the tail end of 'b', reallocating and
* copying its data if necessary. Returns a pointer to the first byte of the
* new data, which is left uninitialized. */
diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h
index 0c12162..bd539c9 100644
--- a/lib/ofpbuf.h
+++ b/lib/ofpbuf.h
@@ -92,6 +92,7 @@ void ofpbuf_prealloc_headroom(struct ofpbuf *, size_t);
void ofpbuf_prealloc_tailroom(struct ofpbuf *, size_t);
void ofpbuf_trim(struct ofpbuf *);
void ofpbuf_padto(struct ofpbuf *, size_t);
+void ofpbuf_shift(struct ofpbuf *, int);
void ofpbuf_clear(struct ofpbuf *);
void *ofpbuf_pull(struct ofpbuf *, size_t);
--
1.7.10.4
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev