mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 07:15:17 +00:00
ofpbuf: Add ofpbuf_new_with_headroom(), ofpbuf_clone_with_headroom().
These new functions simplify an increasingly common usage pattern. Suggested-by: Jesse Gross <jesse@nicira.com>
This commit is contained in:
20
lib/ofpbuf.c
20
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user