__uc_malloc.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* vi: set sw=4 ts=4: */
  2. /* uClibc internal malloc.
  3. Copyright (C) 2007 Denys Vlasenko
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License
  6. version 2 as published by the Free Software Foundation.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA.
  15. */
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <malloc.h>
  19. libc_hidden_proto(__uc_malloc);
  20. libc_hidden_proto(__uc_malloc_failed);
  21. void (*__uc_malloc_failed)(size_t size) = NULL;
  22. /* Seemingly superfluous assigment of NULL above prevents gas error
  23. * ("__uc_malloc_failed can't be equated to common symbol
  24. * __GI___uc_malloc_failed") in libc_hidden_data_def: */
  25. libc_hidden_data_def(__uc_malloc_failed)
  26. void *__uc_malloc(size_t size)
  27. {
  28. void *p;
  29. while (1) {
  30. p = malloc(size);
  31. if (!size || p)
  32. return p;
  33. if (!__uc_malloc_failed)
  34. _exit(1);
  35. __uc_malloc_failed(size);
  36. }
  37. }
  38. libc_hidden_def(__uc_malloc)