stdlib.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_POSIX_STDLIB_H
  19. #define GRUB_POSIX_STDLIB_H 1
  20. #include <grub/mm.h>
  21. #include <grub/misc.h>
  22. #include <grub/safemath.h>
  23. static inline void
  24. free (void *ptr)
  25. {
  26. grub_free (ptr);
  27. }
  28. static inline void *
  29. malloc (grub_size_t size)
  30. {
  31. return grub_malloc (size);
  32. }
  33. static inline void *
  34. calloc (grub_size_t size, grub_size_t nelem)
  35. {
  36. grub_size_t sz;
  37. if (grub_mul (size, nelem, &sz))
  38. return NULL;
  39. return grub_zalloc (sz);
  40. }
  41. static inline void *
  42. realloc (void *ptr, grub_size_t size)
  43. {
  44. return grub_realloc (ptr, size);
  45. }
  46. static inline int
  47. abs (int c)
  48. {
  49. return (c >= 0) ? c : -c;
  50. }
  51. static inline void __attribute__ ((noreturn))
  52. abort (void)
  53. {
  54. grub_abort ();
  55. }
  56. #define strtol grub_strtol
  57. /* for libgcrypt */
  58. #define HAVE_STRTOUL
  59. #define strtoul grub_strtoul
  60. #define strtoull grub_strtoull
  61. #endif