stdlib.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. void *malloc(size_t size)
  37. {
  38. return rt_malloc(size);
  39. }
  40. void free(void *ptr)
  41. {
  42. rt_free(ptr);
  43. }
  44. void *realloc(void *ptr, size_t size)
  45. {
  46. return rt_realloc(ptr, size);
  47. }
  48. void *calloc(size_t nelem, size_t elsize)
  49. {
  50. return rt_calloc(nelem, elsize);
  51. }
  52. #endif