skalibs

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

timed_getlnmax.c (806B)


      1 /* ISC license. */
      2 
      3 #include <sys/types.h>
      4 #include <skalibs/allreadwrite.h>
      5 #include <skalibs/buffer.h>
      6 #include <skalibs/functypes.h>
      7 #include <skalibs/skamisc.h>
      8 #include <skalibs/unix-timed.h>
      9 
     10 struct blah_s
     11 {
     12   buffer *b ;
     13   char *d ;
     14   size_t max ;
     15   size_t w ;
     16   char sep ;
     17 } ;
     18 
     19 static int getfd (struct blah_s *blah)
     20 {
     21   return buffer_fd(blah->b) ;
     22 }
     23 
     24 static ssize_t get (struct blah_s *blah)
     25 {
     26   return sanitize_read(getlnmax(blah->b, blah->d, blah->max, &blah->w, blah->sep)) ;
     27 }
     28 
     29 ssize_t timed_getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep, tain const *deadline, tain *stamp)
     30 {
     31   struct blah_s blah = { .b = b, .d = d, .max = max, .w = *w, .sep = sep } ;
     32   ssize_t r = timed_get(&blah, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ;
     33   *w = blah.w ;
     34   return r ;
     35 }