unixmessage_receiver_free.c (770B)
1 /* ISC license. */ 2 3 #include <sys/types.h> 4 #include <skalibs/cbuffer.h> 5 #include <skalibs/stralloc.h> 6 #include <skalibs/djbunix.h> 7 #include <skalibs/unixmessage.h> 8 9 void unixmessage_receiver_free (unixmessage_receiver *b) 10 { 11 size_t maindatalen = b->maindata.len ; 12 int h ; 13 b->fd = -1 ; 14 stralloc_free(&b->maindata) ; 15 h = maindatalen != b->mainlen || b->auxdata.len != b->auxlen || cbuffer_len(&b->auxb) ; 16 if (h) 17 { 18 size_t n = b->auxdata.len / sizeof(int) ; 19 while (n--) fd_close(((int *)b->auxdata.s)[n]) ; 20 } 21 stralloc_free(&b->auxdata) ; 22 if (h) 23 { 24 size_t n = cbuffer_len(&b->auxb) / sizeof(int) ; 25 if (n) 26 { 27 int fds[n] ; 28 cbuffer_get(&b->auxb, (char *)fds, n * sizeof(int)) ; 29 while (n--) fd_close(fds[n]) ; 30 } 31 } 32 }