-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.h
28 lines (22 loc) · 981 Bytes
/
utils.h
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
// Kuter Dinel 2021
// Random utilies that don't have anywhere better to go.
#ifndef UTILS_H
#define UTILS_H
#include <stddef.h>
// The macro that makes possible to get a struct from a pointer to one
// of it's fields. Used for our linked lists.
#define containerof(ptr, type, member) \
({ \
const typeof(((type *)0)->member) *_ptr_value = (ptr); \
(type *)((void *)_ptr_value - offsetof(type, member)); \
})
#define COMMA(v) v,
#define STR_COMMA(v) #v,
// malloc that you can assume will always return a valid pointer.
// we might add a byte counting function later.
void *dmalloc(size_t size);
void *dzmalloc(size_t size);
#define nnew(type) (type *)dzmalloc(sizeof(type))
void writeLong(char *buffer, unsigned long num, size_t bytes);
void writeInt(char *buffer, unsigned long num, size_t bytes);
#endif