-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbufread.h
More file actions
37 lines (31 loc) · 793 Bytes
/
Copy pathbufread.h
File metadata and controls
37 lines (31 loc) · 793 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
#ifndef BUFREAD_H
#define BUFREAD_H
#include <stddef.h>
#include <sys/types.h>
#include <stdbool.h>
#define BUFFER_CAPACITY 4096
typedef struct
{
char buffer[BUFFER_CAPACITY];
size_t pos;
size_t length;
int socket;
bool eof;
int error;
} bufreader_t;
/**
* Initialize a buffered reader for the given socket.
*/
bufreader_t *br_init(int socket);
/**
* Read a line from the buffer reader into a newly allocated buffer.
* The returned line is null-terminated and includes the newline character.
* Returns the length of the line (including the '\n'), or -1 on error.
* The caller is responsible for freeing `*dest`.
*/
ssize_t br_readline(bufreader_t *r, char **dest);
/**
* Free the buffer reader and its resources.
*/
void br_free(bufreader_t *r);
#endif // BUFREAD_H