-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.hpp
More file actions
34 lines (26 loc) · 974 Bytes
/
buffer.hpp
File metadata and controls
34 lines (26 loc) · 974 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define BUFLEN 4096
#define HEADER_TERMINATOR "\r\n\r\n"
#define HEADER_TERMINATOR_SIZE (sizeof(HEADER_TERMINATOR) - 1)
#define CONTENT_LENGTH "Content-Length: "
#define CONTENT_LENGTH_SIZE (sizeof(CONTENT_LENGTH) - 1)
typedef struct {
char *data;
size_t size;
} buffer;
// initializes a buffer
buffer buffer_init(void);
// destroys a buffer
void buffer_destroy(buffer *buffer);
// adds data of size data_size to a buffer
void buffer_add(buffer *buffer, const char *data, size_t data_size);
// checks if a buffer is empty
int buffer_is_empty(buffer *buffer);
// finds data of size data_size in a buffer and returns its position
int buffer_find(buffer *buffer, const char *data, size_t data_size);
// finds data of size data_size in a buffer in a
// case-insensitive fashion and returns its position
int buffer_find_insensitive(buffer *buffer, const char *data, size_t data_size);