Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/include/rc_util.h
4246 views
1
#ifndef RC_UTIL_H
2
#define RC_UTIL_H
3
4
#include "rc_export.h"
5
6
#include <stddef.h>
7
#include <stdint.h>
8
9
RC_BEGIN_C_DECLS
10
11
/**
12
* A block of memory for variable length data (like strings and arrays).
13
*/
14
typedef struct rc_buffer_chunk_t {
15
/* The current location where data is being written */
16
uint8_t* write;
17
/* The first byte past the end of data where writing cannot occur */
18
uint8_t* end;
19
/* The first byte of the data */
20
uint8_t* start;
21
/* The next block in the allocated memory chain */
22
struct rc_buffer_chunk_t* next;
23
}
24
rc_buffer_chunk_t;
25
26
/**
27
* A preallocated block of memory for variable length data (like strings and arrays).
28
*/
29
typedef struct rc_buffer_t {
30
/* The chunk data (will point at the local data member) */
31
struct rc_buffer_chunk_t chunk;
32
/* Small chunk of memory pre-allocated for the chunk */
33
uint8_t data[256];
34
}
35
rc_buffer_t;
36
37
void rc_buffer_init(rc_buffer_t* buffer);
38
void rc_buffer_destroy(rc_buffer_t* buffer);
39
uint8_t* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount);
40
void rc_buffer_consume(rc_buffer_t* buffer, const uint8_t* start, uint8_t* end);
41
void* rc_buffer_alloc(rc_buffer_t* buffer, size_t amount);
42
char* rc_buffer_strcpy(rc_buffer_t* buffer, const char* src);
43
char* rc_buffer_strncpy(rc_buffer_t* buffer, const char* src, size_t len);
44
45
uint32_t rc_djb2(const char* input);
46
47
void rc_format_md5(char checksum[33], const uint8_t digest[16]);
48
49
RC_END_C_DECLS
50
51
#endif /* RC_UTIL_H */
52
53