1#ifndef _KERNEL_LIBKERN_LIBKERN_H
2#define _KERNEL_LIBKERN_LIBKERN_H
3
4#include <libkern/kassert.h>
5#include <libkern/mem.h>
6#include <libkern/types.h>
7
8#define KB (1024)
9#define MB (1024 * 1024)
10
11/**
12 * SHORTCUTS
13 */
14
15#define TEST_FLAG(val, flag) (((val) & (flag)) == (flag))
16
17int stoi(void* str, int len);
18void htos(uint32_t hex, char str[]);
19void dtos(uint32_t dec, char str[]);
20void reverse(char s[]);
21size_t strlen(const char* s);
22int strcmp(const char* a, const char* b);
23int strncmp(const char* a, const char* b, uint32_t num);
24bool str_validate_len(const char* c, size_t len);
25
26size_t ptrarr_len(const char** s);
27bool ptrarr_validate_len(const char** s, size_t len);
28
29#ifndef max
30#define max(a, b) \
31 ({ __typeof__ (a) _a = (a); \
32 __typeof__ (b) _b = (b); \
33 _a > _b ? _a : _b; })
34#endif /* max */
35
36#ifndef min
37#define min(a, b) \
38 ({ __typeof__ (a) _a = (a); \
39 __typeof__ (b) _b = (b); \
40 _a < _b ? _a : _b; })
41#endif /* min */
42
43#define ROUND_CEIL(a, b) (((a) + ((b)-1)) & ~((b)-1))
44#define ROUND_FLOOR(a, b) ((a) & ~((b)-1))
45
46#endif // _KERNEL_LIBKERN_LIBKERN_H