*/
#include <config.h>
-#include "ofpbuf.h"
+#include "openvswitch/ofpbuf.h"
#include <stdlib.h>
#include <string.h>
#include "openvswitch/dynamic-string.h"
-#include "netdev-dpdk.h"
#include "util.h"
static void
b->source = source;
b->header = NULL;
b->msg = NULL;
- list_poison(&b->list_node);
+ ovs_list_poison(&b->list_node);
}
static void
ofpbuf_put_zeros(struct ofpbuf *b, size_t size)
{
void *dst = ofpbuf_put_uninit(b, size);
- memset(dst, 0, size);
+ nullable_memset(dst, 0, size);
return dst;
}
return dst;
}
+/* Inserts the 'n' bytes of 'data' into 'b' starting at the given 'offset',
+ * moving data forward as necessary to make room.
+ *
+ * 'data' must not point inside 'b'. */
+void
+ofpbuf_insert(struct ofpbuf *b, size_t offset, const void *data, size_t n)
+{
+ if (offset < b->size) {
+ ofpbuf_put_uninit(b, n); /* b->size gets increased. */
+ memmove((char *) b->data + offset + n, (char *) b->data + offset,
+ b->size - offset - n);
+ memcpy((char *) b->data + offset, data, n);
+ } else {
+ ovs_assert(offset == b->size);
+ ofpbuf_put(b, data, n);
+ }
+}
+
/* Returns the data in 'b' as a block of malloc()'d memory and frees the buffer
* within 'b'. (If 'b' itself was dynamically allocated, e.g. with
* ofpbuf_new(), then it should still be freed with, e.g., ofpbuf_delete().) */