X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fofpbuf.c;h=bf5567251066a12bb7f05e9c45339617b48e5fe3;hb=9ea5d2d58ba8783271d096d417082a8372b87c5d;hp=5693eefda6af036bb0f3ca797c98d2a5ac5a3cdf;hpb=d295e8e97acae13552a5b220d3fbcff8201064a2;p=openvswitch diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 5693eefd..bf556725 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -75,12 +75,32 @@ ofpbuf_new(size_t size) return b; } +/* Creates and returns a new ofpbuf with an initial capacity of 'size + + * headroom' bytes, reserving the first 'headroom' bytes as headroom. */ +struct ofpbuf * +ofpbuf_new_with_headroom(size_t size, size_t headroom) +{ + struct ofpbuf *b = ofpbuf_new(size + headroom); + ofpbuf_reserve(b, headroom); + return b; +} + struct ofpbuf * ofpbuf_clone(const struct ofpbuf *buffer) { return ofpbuf_clone_data(buffer->data, buffer->size); } +/* Creates and returns a new ofpbuf whose data are copied from 'buffer'. The + * returned ofpbuf will additionally have 'headroom' bytes of headroom. */ +struct ofpbuf * +ofpbuf_clone_with_headroom(const struct ofpbuf *buffer, size_t headroom) +{ + struct ofpbuf *b = ofpbuf_new_with_headroom(buffer->size, headroom); + ofpbuf_put(b, buffer->data, buffer->size); + return b; +} + struct ofpbuf * ofpbuf_clone_data(const void *data, size_t size) {