rb_read.c
570 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
38
39
40
41
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "ringbuffer.h"
ssize_t
rbRead(Ringbuffer this, int fd)
{
ssize_t rrsize = 0;
size_t rsize = this->bsize - this->bused;
if (0 == rsize) {
errno = ERBOVRFL;
return -1;
}
rrsize = read(fd, this->buffer + this->bend, rsize);
switch (rrsize) {
case 0:
rrsize = -2;
case -1:
break;
default:
this->bend += rrsize;
this->bused += rrsize;
if (this->bend >= this->bsize) {
this->bend -= this->bsize;
}
break;
}
return rrsize;
}
// vim: set ts=4 sw=4: