1 /*
2  * Copyright (c) 2008-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <lk/compiler.h>
11 #include <sys/types.h>
12 #include <stddef.h>
13 #include <malloc.h>
14 #include <endian.h>
15 #include <rand.h>
16 #include <arch/defines.h>
17 
18 __BEGIN_CDECLS
19 
20 int atoi(const char *num);
21 unsigned int atoui(const char *num);
22 long atol(const char *num);
23 unsigned long atoul(const char *num);
24 unsigned long long atoull(const char *num);
25 
26 long strtol(const char *nptr, char **endptr, int base);
27 long long strtoll(const char *nptr, char **endptr, int base);
28 
29 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
30 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
31 
32 #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
33 #define ROUNDDOWN(a, b) ((a) & ~((b)-1))
34 
35 #define ALIGN(a, b) ROUNDUP(a, b)
36 #define IS_ALIGNED(a, b) (!(((uintptr_t)(a)) & (((uintptr_t)(b))-1)))
37 
38 /* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
39 #define STACKBUF_DMA_ALIGN(var, size) \
40     uint8_t var[ROUNDUP(size, CACHE_LINE)] __ALIGNED(CACHE_LINE);
41 void abort(void) __attribute__((noreturn));
42 void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *));
43 void *bsearch(const void *key, const void *base, size_t num_elems, size_t size,
44               int (*compare)(const void *, const void *));
45 unsigned long int strtoul(const char *nptr, char **endptr, int base);
46 char *getenv(const char *name);
47 int atexit(void (*func)(void));
48 
49 __END_CDECLS
50 
51