-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbyte.c
More file actions
42 lines (35 loc) · 922 Bytes
/
cbyte.c
File metadata and controls
42 lines (35 loc) · 922 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
38
39
40
41
42
#include <stdlib.h>
#include <string.h>
#include "cbyte.h"
uint64 cbyte_init(int cap) {
return cbyte_init64((uint64)cap);
}
uint64 cbyte_init64(uint64 cap) {
return (uint64) malloc(cap);
}
uint64 cbyte_grow_m(uint64 addr, int cap_o, int cap_n) {
return cbyte_grow64_m(addr, (uint64)cap_o, (uint64)cap_n);
}
uint64 cbyte_grow64_m(uint64 addr, uint64 cap_o, uint64 cap_n) {
uint64 addr_n = (uint64) malloc(cap_n);
if (addr_n == 0) {
return addr_n;
}
if (cap_n < cap_o) {
cap_o = cap_n;
}
memcpy((void*)addr_n, (void*)addr, cap_o);
free((void*)addr);
return addr_n;
}
uint64 cbyte_grow_r(uint64 addr, int cap) {
return cbyte_grow64_r(addr, (uint64)cap);
}
uint64 cbyte_grow64_r(uint64 addr, uint64 cap) {
return (uint64) realloc((void*)addr, cap);
}
void cbyte_release(uint64 addr) {
if ((void*)addr != NULL) {
free((void*)addr);
}
}