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