diff options
| author | Ben Pfaff <blp@nicira.com> | 2010-09-01 12:55:38 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2010-09-01 12:55:50 -0700 |
| commit | 68efcbec41b0acfd8bb7579a5d38afd71b6daf7c (patch) | |
| tree | 2cfaa4c9688064bd29a01fdb8c588690e80427cd /lib/ofpbuf.c | |
| parent | f79cb67e689566cfbf3071e0ac0e29923ada5a97 (diff) | |
| download | openvswitch-68efcbec41b0acfd8bb7579a5d38afd71b6daf7c.tar.gz | |
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>
Diffstat (limited to 'lib/ofpbuf.c')
| -rw-r--r-- | lib/ofpbuf.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 5693eefda..bf5567251 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) { |
