OK

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Ben Pfaff
> Sent: Tuesday, 13 June, 2017 00:29
> To: [email protected]
> Cc: Ben Pfaff <[email protected]>
> Subject: [ovs-dev] [PATCH 13/31] ofpbuf: New function ofpbuf_insert().
> 
> This will receive its first users in an upcoming commit.
> 
> Signed-off-by: Ben Pfaff <[email protected]>
> ---
>  include/openvswitch/ofpbuf.h |  1 +
>  lib/ofpbuf.c                 | 18 ++++++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h
> index bc25bb8a1780..6142f4a588e1 100644
> --- a/include/openvswitch/ofpbuf.h
> +++ b/include/openvswitch/ofpbuf.h
> @@ -141,6 +141,7 @@ void ofpbuf_reserve(struct ofpbuf *, size_t);
>  void *ofpbuf_push_uninit(struct ofpbuf *b, size_t);
>  void *ofpbuf_push_zeros(struct ofpbuf *, size_t);
>  void *ofpbuf_push(struct ofpbuf *b, const void *, size_t);
> +void ofpbuf_insert(struct ofpbuf *b, size_t offset, const void *data, 
> size_t);
> 
>  static inline size_t ofpbuf_headroom(const struct ofpbuf *);
>  static inline size_t ofpbuf_tailroom(const struct ofpbuf *);
> diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c
> index 3019c4a95478..d0a68a6e40e4 100644
> --- a/lib/ofpbuf.c
> +++ b/lib/ofpbuf.c
> @@ -461,6 +461,24 @@ ofpbuf_push(struct ofpbuf *b, const void *p, size_t size)
>      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);
> +        memmove((char *) b->data + offset + n, (char *) b->data + offset,
> +                b->size - offset);
> +        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().) 
> */
> --
> 2.10.2
> 
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to