-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSWbuffer.c
More file actions
30 lines (25 loc) · 753 Bytes
/
SWbuffer.c
File metadata and controls
30 lines (25 loc) · 753 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
#include "SWbuffer.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void swBufInit(SWbuffer *b, const SWuint size, const void *data) {
void *_data = malloc(size);
assert(_data);
if (data) {
memcpy(_data, data, size);
}
b->size = size;
b->data = _data;
}
void swBufDestroy(SWbuffer *b) {
free(b->data);
memset(b, 0, sizeof(SWbuffer));
}
void swBufSetData(SWbuffer *b, const SWuint offset, const SWuint size, const void *data) {
assert(b->data);
memcpy((char *)b->data + offset, data, size);
}
void swBufGetData(const SWbuffer *b, const SWuint offset, const SWuint size, void *data) {
assert(b->data);
memcpy(data, (char *)b->data + offset, size);
}