MentOS
0.8.0
The Mentoring Operating System
libc
inc
array.h
Go to the documentation of this file.
1
6
#pragma once
7
8
#ifdef __KERNEL__
10
#define ARRAY_ALLOC kmalloc
12
#define ARRAY_FREE kfree
13
#else
15
#define ARRAY_ALLOC malloc
17
#define ARRAY_FREE free
18
#endif
19
21
#define DECLARE_ARRAY(type, name) \
22
typedef struct arr_##name##_t { \
23
const unsigned size; \
24
type *buffer; \
25
} arr_##name##_t; \
26
arr_##name##_t alloc_arr_##name(unsigned len) \
27
{ \
28
arr_##name##_t a = { len, len > 0 ? ARRAY_ALLOC(sizeof(type) * len) : NULL }; \
29
memset(a.buffer, 0, sizeof(type) * len); \
30
return a; \
31
} \
32
static inline void free_arr_##name(arr_##name##_t *arr) \
33
{ \
34
ARRAY_FREE(arr->buffer); \
35
}
36
37
#undef ARRAY_ALLOC
38
#undef ARRAY_FREE
Generated by
1.9.1