stdlib.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. void *malloc(size_t size)
  53. {
  54. return rt_malloc(size);
  55. }
  56. void free(void *ptr)
  57. {
  58. rt_free(ptr);
  59. }
  60. void *realloc(void *ptr, size_t size)
  61. {
  62. return rt_realloc(ptr, size);
  63. }
  64. void *calloc(size_t nelem, size_t elsize)
  65. {
  66. return rt_calloc(nelem, elsize);
  67. }
  68. #endif