bump version to 1.0.28
[uclibc-ng.git] / libc / stdlib / __uc_malloc.c
blob1e879d59795021adc945c1224ffc9af7ca914140
1 /* uClibc internal malloc.
2 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.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with this library; see the file COPYING.LIB. If
15 not, see <http://www.gnu.org/licenses/>.
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <malloc.h>
24 void (*__uc_malloc_failed)(size_t size) = NULL;
25 /* Seemingly superfluous assigment of NULL above prevents gas error
26 * ("__uc_malloc_failed can't be equated to common symbol
27 * __GI___uc_malloc_failed") in libc_hidden_data_def: */
28 libc_hidden_data_def(__uc_malloc_failed)
30 void *__uc_malloc(size_t size)
32 void *p;
34 while (1) {
35 p = malloc(size);
36 if (!size || p)
37 return p;
38 if (!__uc_malloc_failed)
39 _exit(1);
40 free(p);
41 __uc_malloc_failed(size);
44 libc_hidden_def(__uc_malloc)