diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libunixonacid/unixmessage_sender_free.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libunixonacid/unixmessage_sender_free.c')
-rw-r--r-- | src/libunixonacid/unixmessage_sender_free.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libunixonacid/unixmessage_sender_free.c b/src/libunixonacid/unixmessage_sender_free.c new file mode 100644 index 0000000..797220c --- /dev/null +++ b/src/libunixonacid/unixmessage_sender_free.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> +#include <skalibs/diuint.h> +#include <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <skalibs/unixmessage.h> + +void unixmessage_sender_free (unixmessage_sender_t *b) +{ +#ifdef SKALIBS_HASANCILAUTOCLOSE + { + diuint *offsets = genalloc_s(unsigned int, &b->offsets) ; + unsigned int n = genalloc_len(unsigned int, &b->offsets) ; + int *fds = genalloc_s(int, &b->fds) ; + unsigned int nfds = genalloc_len(int, &b->fds) ; + for (; b->head < n ; b->head++) + { + register unsigned int last = b->head+1 < n ? offsets[b->head+1].right : nfds ; + register unsigned int i = offsets[b->head].right ; + for (; i < last ; i++) if (fds[i] >= 0) fd_close(fds[i]) ; + } + } +#endif + genalloc_free(diuint, &b->offsets) ; + genalloc_free(int, &b->fds) ; + stralloc_free(&b->data) ; + *b = unixmessage_sender_zero ; +} |