stdlib.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 errno = 0;
  18. int atoi(const char* s)
  19. {
  20. long int v=0;
  21. int sign=1;
  22. while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
  23. switch (*s)
  24. {
  25. case '-':
  26. sign=-1;
  27. case '+':
  28. ++s;
  29. }
  30. while ((unsigned int) (*s - '0') < 10u)
  31. {
  32. v=v*10+*s-'0';
  33. ++s;
  34. }
  35. return sign==-1?-v:v;
  36. }
  37. void *malloc(size_t size)
  38. {
  39. return rt_malloc(size);
  40. }
  41. void free(void *ptr)
  42. {
  43. rt_free(ptr);
  44. }
  45. void *realloc(void *ptr, size_t size)
  46. {
  47. return rt_realloc(ptr, size);
  48. }
  49. void *calloc(size_t nelem, size_t elsize)
  50. {
  51. return rt_calloc(nelem, elsize);
  52. }
  53. #endif