2018-02-26 21:04:46 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018, Linaro Ltd.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
2024-03-16 17:53:43 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-02-26 21:04:46 -08:00
|
|
|
*/
|
|
|
|
|
#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
|