Skip to content

Commit

Permalink
lib/ofpbuf: add ofpbuf_use_ds() API
Browse files Browse the repository at this point in the history
Add an API to convert a dynamic string object into ofpbuf.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Sep 1, 2015
1 parent 4ac6dbe commit 37e2372
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/ofpbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ ofpbuf_use(struct ofpbuf *b, void *base, size_t allocated)
ofpbuf_use__(b, base, allocated, 0, OFPBUF_MALLOC);
}

/* Converts ds into ofpbuf 'b'. 'b' contains the 'ds->allocated' bytes of
* memory starting at 'ds->string'. 'ds' should not be modified any more.
* The memory allocated for 'ds' will be freed (with free()) if 'b' is
* resized or freed. */
void
ofpbuf_use_ds(struct ofpbuf *b, const struct ds *ds)
{
ofpbuf_use__(b, ds->string, ds->allocated + 1, ds->length, OFPBUF_MALLOC);
}

/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
* memory starting at 'base'. 'base' should point to a buffer on the stack.
* (Nothing actually relies on 'base' being allocated on the stack. It could
Expand Down
1 change: 1 addition & 0 deletions lib/ofpbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct ofpbuf {
}

void ofpbuf_use(struct ofpbuf *, void *, size_t);
void ofpbuf_use_ds(struct ofpbuf *, const struct ds *);
void ofpbuf_use_stack(struct ofpbuf *, void *, size_t);
void ofpbuf_use_stub(struct ofpbuf *, void *, size_t);
void ofpbuf_use_const(struct ofpbuf *, const void *, size_t);
Expand Down

0 comments on commit 37e2372

Please sign in to comment.