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 double atof(const char *num);
22 unsigned int atoui(const char *num);
23 long atol(const char *num);
24 unsigned long atoul(const char *num);
25 unsigned long long atoull(const char *num);
26 
27 long strtol(const char *nptr, char **endptr, int base);
28 long long strtoll(const char *nptr, char **endptr, int base);
29 
30 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
31 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
32 
33 #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
34 #define ROUNDDOWN(a, b) ((a) & ~((b)-1))
35 
36 #define ALIGN(a, b) ROUNDUP(a, b)
37 #define IS_ALIGNED(a, b) (!(((uintptr_t)(a)) & (((uintptr_t)(b))-1)))
38 
39 /* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
40 #define STACKBUF_DMA_ALIGN(var, size) \
41     uint8_t var[ROUNDUP(size, CACHE_LINE)] __ALIGNED(CACHE_LINE);
42 void abort(void) __attribute__((noreturn));
43 void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *));
44 void *bsearch(const void *key, const void *base, size_t num_elems, size_t size,
45               int (*compare)(const void *, const void *));
46 unsigned long int strtoul(const char *nptr, char **endptr, int base);
47 char *getenv(const char *name);
48 int atexit(void (*func)(void));
49 
50 __END_CDECLS
51 
52