forked from uyjulian/zbspac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteArray.c
40 lines (33 loc) · 829 Bytes
/
ByteArray.c
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
/**
* @file ByteArray.c
* @brief A heap-allocated byte array that knows how long itself is.
* @copyright Covered by 2-clause BSD, please refer to license.txt.
* @author CloudiDust
* @date 2010.02
*/
#include <stdlib.h>
#include <string.h>
#include "ByteArray.h"
struct ByteArray {
byte* data;
u32 length;
};
ByteArray* newByteArray(u32 length) {
ByteArray* array = malloc(sizeof(ByteArray));
array->data = malloc(sizeof(byte) * length);
memset(array->data, 0, length);
array->length = length;
return array;
}
void deleteByteArray(ByteArray* array) {
if (!array) return;
if (array->data) free(array->data);
free(array);
array = NULL;
}
byte* baData(const ByteArray* array) {
return array->data;
}
u32 baLength(const ByteArray* array) {
return array->length;
}