diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-03-16 12:31:17 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-03-16 12:31:17 +0000 |
commit | 6bae0b3d69c7968586afc73827b5844c6a23873f (patch) | |
tree | 03db0c9ff6dfa2a92ce90f26256426e4ef4404c7 | |
parent | 4684272897e351ed21f82a0ef84bc94194b4d538 (diff) | |
download | skalibs-6bae0b3d69c7968586afc73827b5844c6a23873f.tar.xz |
Add genqdyn_unpush, bufalloc_unput
-rw-r--r-- | src/include/skalibs/bufalloc.h | 1 | ||||
-rw-r--r-- | src/include/skalibs/genqdyn.h | 1 | ||||
-rw-r--r-- | src/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 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 <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 ; +} |