merge
[dcpu16] / common.h
1 #ifndef COMMON_H_QPRCB1BH
2 #define COMMON_H_QPRCB1BH
3
4 #include <stdlib.h>
5 #include <time.h>
6
7 struct dynamic_array {
8 size_t entry_size;
9 size_t grow_size;
10 size_t allocated;
11 size_t entries;
12 void *a;
13 };
14
15 #define DYNARRAY_ITEM(da, index) ( (char *)(da).a + ( (da).entry_size * index ) )
16
17 int dynarray_init(struct dynamic_array *da, size_t entry_size, size_t grow_size);
18 struct dynamic_array *dynarray_new(size_t entry_size, size_t grow_size);
19 void *dynarray_add(struct dynamic_array *da, void *item);
20 void dynarray_empty(struct dynamic_array *da, void (*free_element)(void *));
21
22 int str_to_word(char *s);
23
24 char *strqtok_r(char *str, const char *sep, int esc, const char *quote, char **lastq, char **lasts);
25
26 int gettimespecofday(struct timespec *ts);
27 int timespec_add(struct timespec *result, const struct timespec *x);
28 int timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y);
29
30 #endif /* COMMON_H_QPRCB1BH */