 char *buf, size_t len) {  int count = 0;   while ((count < len) && (f->len > 0)) {    int nread;    if (f->tail <= f->head) {    nread = len - count;    if (nread > f->n - f->head)     nread = f->n - f->head;   }   else {    nread = f->tail - f->head;    if (nread > len - count)     nread = len - count;   }    memcpy(buf, f->data + f->head, nread);    count += nread;   buf += nread;   f->len -= nread;   f->head += nread;   f->head %= f->n;  }   return count; }  