1
0

stdlib.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <rtthread.h>
  11. #if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
  12. #include "stdlib.h"
  13. int atoi(const char* s)
  14. {
  15. long int v=0;
  16. int sign=1;
  17. while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
  18. switch (*s)
  19. {
  20. case '-':
  21. sign=-1;
  22. case '+':
  23. ++s;
  24. }
  25. while ((unsigned int) (*s - '0') < 10u)
  26. {
  27. v=v*10+*s-'0';
  28. ++s;
  29. }
  30. return sign==-1?-v:v;
  31. }
  32. long int atol(const char* s)
  33. {
  34. long int v=0;
  35. int sign=0;
  36. while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
  37. switch (*s)
  38. {
  39. case '-': sign=-1;
  40. case '+': ++s;
  41. }
  42. while ((unsigned int) (*s - '0') < 10u)
  43. {
  44. v=v*10+*s-'0'; ++s;
  45. }
  46. return sign?-v:v;
  47. }
  48. #ifdef RT_USING_HEAP
  49. void *malloc(size_t size)
  50. {
  51. return rt_malloc(size);
  52. }
  53. void free(void *ptr)
  54. {
  55. rt_free(ptr);
  56. }
  57. void *realloc(void *ptr, size_t size)
  58. {
  59. return rt_realloc(ptr, size);
  60. }
  61. void *calloc(size_t nelem, size_t elsize)
  62. {
  63. return rt_calloc(nelem, elsize);
  64. }
  65. #endif
  66. #endif