skalibs

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

buffer_timed_get.c (630B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/functypes.h>
      4 #include <skalibs/buffer.h>
      5 #include <skalibs/unix-timed.h>
      6 
      7 struct blah_s
      8 {
      9   buffer *b ;
     10   char *s ;
     11   size_t len ;
     12   size_t w ;
     13 } ;
     14 
     15 static int getfd (struct blah_s *blah)
     16 {
     17   return buffer_fd(blah->b) ;
     18 }
     19 
     20 static ssize_t get (struct blah_s *blah)
     21 {
     22   return buffer_getall(blah->b, blah->s, blah->len, &blah->w) ;
     23 }
     24 
     25 size_t buffer_timed_get (buffer *b, char *s, size_t len, tain const *deadline, tain *stamp)
     26 {
     27   struct blah_s blah = { .b = b, .s = s, .len = len, .w = 0 } ;
     28   timed_get(&blah, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ;
     29   return blah.w ;
     30 }