forked from linux-msm/cdba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcirc_buf.h
33 lines (25 loc) · 779 Bytes
/
circ_buf.h
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
/*
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CIRC_BUF_H__
#define __CIRC_BUF_H__
#include <stdlib.h>
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#define CIRC_BUF_SIZE 16384
struct circ_buf {
char buf[CIRC_BUF_SIZE];
size_t head;
size_t tail;
};
#define CIRC_AVAIL(circ) (((circ)->head - (circ)->tail) & (CIRC_BUF_SIZE - 1))
#define CIRC_SPACE(circ) (((circ)->tail - (circ)->head - 1) & (CIRC_BUF_SIZE - 1))
#define CIRC_SPACE_TO_END(circ) MIN(CIRC_SPACE(circ), CIRC_BUF_SIZE - (circ)->head)
ssize_t circ_fill(int fd, struct circ_buf *circ);
size_t circ_peak(struct circ_buf *circ, void *buf, size_t len);
size_t circ_read(struct circ_buf *circ, void *buf, size_t len);
#endif