1
0

stdlib.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * File : stdlib.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2008-08-14 Bernard the first version
  13. */
  14. #include <rtthread.h>
  15. #if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
  16. #include "stdlib.h"
  17. int atoi(const char* s)
  18. {
  19. long int v=0;
  20. int sign=1;
  21. while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
  22. switch (*s)
  23. {
  24. case '-':
  25. sign=-1;
  26. case '+':
  27. ++s;
  28. }
  29. while ((unsigned int) (*s - '0') < 10u)
  30. {
  31. v=v*10+*s-'0';
  32. ++s;
  33. }
  34. return sign==-1?-v:v;
  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. #ifdef RT_USING_HEAP
  53. void *malloc(size_t size)
  54. {
  55. return rt_malloc(size);
  56. }
  57. void free(void *ptr)
  58. {
  59. rt_free(ptr);
  60. }
  61. void *realloc(void *ptr, size_t size)
  62. {
  63. return rt_realloc(ptr, size);
  64. }
  65. void *calloc(size_t nelem, size_t elsize)
  66. {
  67. return rt_calloc(nelem, elsize);
  68. }
  69. #endif
  70. #endif