skalibs

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

unixmessage_receiver_hasmsginbuf.c (512B)


      1 /* ISC license. */
      2 
      3 #include <stdint.h>
      4 #include <sys/uio.h>
      5 #include <skalibs/uint32.h>
      6 #include <skalibs/siovec.h>
      7 #include <skalibs/cbuffer.h>
      8 #include <skalibs/unixmessage.h>
      9 
     10 int unixmessage_receiver_hasmsginbuf (unixmessage_receiver const *b)
     11 {
     12   size_t len = cbuffer_len(&b->mainb) ;
     13   uint32_t mainlen ;
     14   char pack[4] ;
     15   struct iovec v[2] ;
     16   if (len < 6) return 0 ;
     17   cbuffer_rpeek(&b->mainb, v) ;
     18   siovec_gather(v, 2, pack, 4) ;
     19   uint32_unpack_big(pack, &mainlen) ;
     20   return len - 6 >= mainlen ;
     21 }