nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

slurpclose.c (559B)


      1 #include "slurpclose.h"
      2 
      3 #include "stralloc.h"
      4 #include "readwrite.h"
      5 #include "error.h"
      6 
      7 /* This Bernstein slurpclose strides across the input,
      8  * at the pitch specified in bufsize. It returns the last
      9  * return of read() so that that might be */
     10 int slurpclose(int fd, stralloc *sa, int bufsize)
     11 {
     12   int r;
     13   for (;;) {
     14     if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
     15     r = read(fd,sa->s + sa->len,bufsize);
     16     if (r == -1) if (errno == error_intr) continue;
     17     if (r == 0 || r == -1) { close(fd); return r; }
     18     sa->len += r;
     19   }
     20 }