read.c
471 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "cbuf.h"
ssize_t
cbufRead(Cbuf this, int fd)
{
ssize_t rrsize = 0;
size_t rsize = cbufGetFree(this);
if (0 == rsize) {
errno = ECBUFOVFL;
return -1;
}
rrsize = read(fd, cbufGetWrite(this), rsize);
switch (rrsize) {
case 0:
rrsize = -2;
// DROP THROUGH
case -1:
break;
default:
cbufIncWrite(this, rrsize);
break;
}
return rrsize;
}
// vim: set ts=4 sw=4: