unixmessage_unput.c (737B)
1 /* ISC license. */ 2 3 #include <skalibs/genalloc.h> 4 #include <skalibs/disize.h> 5 #include <skalibs/djbunix.h> 6 #include <skalibs/unixmessage.h> 7 8 int unixmessage_unput_and_maybe_drop (unixmessage_sender *b, int drop) 9 { 10 disize *start ; 11 size_t n = genalloc_len(disize, &b->offsets) ; 12 size_t i ; 13 int *fds ; 14 if (!n) return 0 ; 15 start = genalloc_s(disize, &b->offsets) + n - 1 ; 16 fds = genalloc_s(int, &b->fds) + start->right ; 17 i = genalloc_len(int, &b->fds) - start->right ; 18 while (i--) 19 if (fds[i] < 0) (*b->closecb)(-(fds[i]+1), b->closecbdata) ; 20 else if (drop) fd_close(fds[i]) ; 21 b->data.len = start->left ; 22 genalloc_setlen(int, &b->fds, start->right) ; 23 genalloc_setlen(disize, &b->offsets, n-1) ; 24 return 1 ; 25 }