From 6bae0b3d69c7968586afc73827b5844c6a23873f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 16 Mar 2018 12:31:17 +0000 Subject: Add genqdyn_unpush, bufalloc_unput --- src/include/skalibs/bufalloc.h | 1 + src/include/skalibs/genqdyn.h | 1 + src/libdatastruct/genqdyn_unpush.c | 12 ++++++++++++ 3 files changed, 14 insertions(+) create mode 100644 src/libdatastruct/genqdyn_unpush.c diff --git a/src/include/skalibs/bufalloc.h b/src/include/skalibs/bufalloc.h index 6e80881..b87f125 100644 --- a/src/include/skalibs/bufalloc.h +++ b/src/include/skalibs/bufalloc.h @@ -24,6 +24,7 @@ extern void bufalloc_init (bufalloc *, ssize_t (*)(int, char const *, size_t), i #define bufalloc_put(ba, s, n) stralloc_catb(&(ba)->x, s, n) #define bufalloc_puts(ba, s) stralloc_cats(&(ba)->x, s) #define bufalloc_putv(ba, v, n) stralloc_catv(&(ba)->x, v, n) +#define bufalloc_unput(ba, n) ((ba)->x.len -= (n)) #define bufalloc_fd(ba) ((ba)->fd) extern int bufalloc_getfd (bufalloc const *) gccattr_pure ; extern int bufalloc_flush (bufalloc *) ; diff --git a/src/include/skalibs/genqdyn.h b/src/include/skalibs/genqdyn.h index 0f7751b..ca7ec7e 100644 --- a/src/include/skalibs/genqdyn.h +++ b/src/include/skalibs/genqdyn.h @@ -26,6 +26,7 @@ extern void genqdyn_init (genqdyn *, size_t, unsigned int, unsigned int) ; extern void genqdyn_free (genqdyn *) ; extern int genqdyn_push (genqdyn *, void const *) ; +extern int genqdyn_unpush (genqdyn *) ; #define GENQDYN_PEEK(type, g) ((type *)((g)->queue.s + (g)->esize * (g)->head)) #define genqdyn_peek(g) GENQDYN_PEEK(void, (g)) extern int genqdyn_pop(genqdyn *) ; diff --git a/src/libdatastruct/genqdyn_unpush.c b/src/libdatastruct/genqdyn_unpush.c new file mode 100644 index 0000000..10100c9 --- /dev/null +++ b/src/libdatastruct/genqdyn_unpush.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include +#include +#include + +int genqdyn_unpush (genqdyn *g) +{ + if (g->queue.len < g->esize) return (errno = EINVAL, 0) ; + g->queue.len -= g->esize ; + return 1 ; +} -- cgit v1.2.3