import migen in litex/gen
[litex.git] / litex / soc / misoc / software / include / base / stdlib.h
1 /*
2 * MiSoC
3 * Copyright (C) 2007, 2008, 2009, 2011 Sebastien Bourdeauducq
4 * Copyright (C) Linux kernel developers
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, version 3 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef __STDLIB_H
20 #define __STDLIB_H
21
22 #include <stddef.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #define PRINTF_ZEROPAD 1 /* pad with zero */
29 #define PRINTF_SIGN 2 /* unsigned/signed long */
30 #define PRINTF_PLUS 4 /* show plus */
31 #define PRINTF_SPACE 8 /* space if plus */
32 #define PRINTF_LEFT 16 /* left justified */
33 #define PRINTF_SPECIAL 32 /* 0x */
34 #define PRINTF_LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
35
36 #define likely(x) x
37 #define unlikely(x) x
38
39 static inline int abs(int x)
40 {
41 return x > 0 ? x : -x;
42 }
43
44 static inline long int labs(long int x)
45 {
46 return x > 0 ? x : -x;
47 }
48
49 unsigned long strtoul(const char *nptr, char **endptr, int base);
50 long strtol(const char *nptr, char **endptr, int base);
51 double strtod(const char *str, char **endptr);
52
53 int skip_atoi(const char **s);
54 static inline int atoi(const char *nptr) {
55 return strtol(nptr, NULL, 10);
56 }
57 static inline long atol(const char *nptr) {
58 return (long)atoi(nptr);
59 }
60 char *number(char *buf, char *end, unsigned long num, int base, int size, int precision, int type);
61
62 #define RAND_MAX 2147483647
63
64 unsigned int rand(void);
65 void srand(unsigned int seed);
66 void abort(void) __attribute__((noreturn));
67
68 void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
69
70 /*
71 * The following functions are not provided by this library.
72 */
73
74 char *getenv(const char *name);
75
76 void *malloc(size_t size);
77 void free(void *ptr);
78 void *realloc(void *ptr, size_t size);
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif /* __STDLIB_H */