skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 6bae0b3d69c7968586afc73827b5844c6a23873f
parent 4684272897e351ed21f82a0ef84bc94194b4d538
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri, 16 Mar 2018 12:31:17 +0000

 Add genqdyn_unpush, bufalloc_unput

Diffstat:
Msrc/include/skalibs/bufalloc.h | 1+
Msrc/include/skalibs/genqdyn.h | 1+
Asrc/libdatastruct/genqdyn_unpush.c | 12++++++++++++
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/errno.h> +#include <skalibs/stralloc.h> +#include <skalibs/genqdyn.h> + +int genqdyn_unpush (genqdyn *g) +{ + if (g->queue.len < g->esize) return (errno = EINVAL, 0) ; + g->queue.len -= g->esize ; + return 1 ; +}