libdatatypes 0.3.2
Abstract datatypes for C.
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1/***************************************************************************
2 begin........: April 2012
3 copyright....: Sebastian Fedrau
4 email........: sebastian.fedrau@gmail.com
5 ***************************************************************************/
6
7/***************************************************************************
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License v3 as published by
10 the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License v3 for more details.
16 ***************************************************************************/
22#include <stdlib.h>
23#include <stdio.h>
24#include <stdbool.h>
25#include <stdint.h>
26#include <unistd.h>
27
28#ifndef BUFFER_H
29#define BUFFER_H
30
36typedef struct Buffer
37{
39 char *data;
41 size_t max_size;
43 size_t len;
45 size_t msize;
47 bool valid;
48} Buffer;
49
56Buffer *buffer_new(size_t max_size);
57
64void buffer_init(Buffer *buf, size_t max_size);
65
71void buffer_free(Buffer *buf);
72
78void buffer_destroy(Buffer *buf);
79
85void buffer_clear(Buffer *buf);
86
93size_t buffer_len(const Buffer *buf);
94
101bool buffer_is_valid(const Buffer *buf);
102
109bool buffer_is_empty(const Buffer *buf);
110
119bool buffer_fill(Buffer *buf, const char *data, size_t len);
120
129ssize_t buffer_fill_from_fd(Buffer *buf, int fd, size_t count);
130
139bool buffer_read_line(Buffer *buf, char **dst, size_t *len);
140
149bool buffer_flush(const Buffer *buf, char **dst, size_t *len);
150
157char *buffer_to_string(const Buffer *buf);
158
159#endif
160
size_t len
Definition buffer.h:43
Buffer * buffer_new(size_t max_size)
Definition buffer.c:41
ssize_t buffer_fill_from_fd(Buffer *buf, int fd, size_t count)
Definition buffer.c:189
bool buffer_flush(const Buffer *buf, char **dst, size_t *len)
Definition buffer.c:267
bool buffer_fill(Buffer *buf, const char *data, size_t len)
Definition buffer.c:153
bool buffer_is_empty(const Buffer *buf)
Definition buffer.c:123
size_t msize
Definition buffer.h:45
bool valid
Definition buffer.h:47
char * buffer_to_string(const Buffer *buf)
Definition buffer.c:287
size_t buffer_len(const Buffer *buf)
Definition buffer.c:105
size_t max_size
Definition buffer.h:41
void buffer_destroy(Buffer *buf)
Definition buffer.c:87
bool buffer_read_line(Buffer *buf, char **dst, size_t *len)
Definition buffer.c:240
void buffer_clear(Buffer *buf)
Definition buffer.c:96
bool buffer_is_valid(const Buffer *buf)
Definition buffer.c:115
void buffer_init(Buffer *buf, size_t max_size)
Definition buffer.c:59
char * data
Definition buffer.h:39
void buffer_free(Buffer *buf)
Definition buffer.c:79
A byte buffer. If the data exceeds the maximum length the buffer becomes invalid and new data is igno...
Definition buffer.h:37