aboutsummaryrefslogtreecommitdiff
path: root/djb/buffer_get.c
blob: ed51707d35d595b8cf048606a6c185c0137d0611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "buffer.h"
#include <errno.h>

int buffer_getc(buffer* b, char *s) /*EXTRACT_INCL*/ {
  if (b->p >= b->n) {
    int r;
    while ((r=b->op(b->fd, b->x, b->a)) <0)
      if (errno != EINTR) break;

    if (r<=0) return r;
    b->p = 0; 
    b->n = r;
  }
  *s = b->x[b->p]; 
  b->p++;
  return 1;
}