xref: /nrf52832-nimble/rt-thread/components/libc/compilers/minilibc/stdlib.c (revision 167494296f0543431a51b6b1b83e957045294e05)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2008-08-14     Bernard      the first version
9  */
10 
11 #include <rtthread.h>
12 
13 #if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
14 #include "stdlib.h"
15 
16 int atoi(const char* s)
17 {
18 	long int v=0;
19 	int sign=1;
20 	while ( *s == ' '  ||  (unsigned int)(*s - 9) < 5u) s++;
21 	switch (*s)
22 	{
23 	case '-':
24 		sign=-1;
25 	case '+':
26 		++s;
27 	}
28 	while ((unsigned int) (*s - '0') < 10u)
29 	{
30 		v=v*10+*s-'0';
31 		++s;
32 	}
33 	return sign==-1?-v:v;
34 }
35 
36 long int atol(const char* s)
37 {
38 	long int v=0;
39 	int sign=0;
40 	while ( *s == ' '  ||  (unsigned int)(*s - 9) < 5u) ++s;
41 	switch (*s)
42 	{
43 		case '-': sign=-1;
44 		case '+': ++s;
45 	}
46 	while ((unsigned int) (*s - '0') < 10u)
47 	{
48 		v=v*10+*s-'0'; ++s;
49 	}
50 	return sign?-v:v;
51 }
52 
53 #ifdef RT_USING_HEAP
54 void *malloc(size_t size)
55 {
56 	return rt_malloc(size);
57 }
58 
59 void free(void *ptr)
60 {
61 	rt_free(ptr);
62 }
63 
64 void *realloc(void *ptr, size_t size)
65 {
66 	return rt_realloc(ptr, size);
67 }
68 
69 void *calloc(size_t nelem, size_t elsize)
70 {
71 	return rt_calloc(nelem, elsize);
72 }
73 #endif
74 
75 #endif
76