Add a helper to sort the gobuffer. Trivial wrapper around qsort(). Signed-off-by: Daniel Xu <dxu@xxxxxxxxx> --- gobuffer.c | 5 +++++ gobuffer.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/gobuffer.c b/gobuffer.c index 02b2084..4655339 100644 --- a/gobuffer.c +++ b/gobuffer.c @@ -102,6 +102,11 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest) } } +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *)) +{ + qsort((void *)gb->entries, gb->nr_entries, size, compar); +} + const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size) { z_stream z = { diff --git a/gobuffer.h b/gobuffer.h index a12c5c8..cd218b6 100644 --- a/gobuffer.h +++ b/gobuffer.h @@ -21,6 +21,8 @@ void __gobuffer__delete(struct gobuffer *gb); void gobuffer__copy(const struct gobuffer *gb, void *dest); +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *)); + int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len); int gobuffer__allocate(struct gobuffer *gb, unsigned int len); -- 2.44.0