struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / pic14 / libc / memfreemax.c
blobe57ace22d984a422f0d4619110dc795e7bdaa96a
1 /*-------------------------------------------------------------------------
2 memfreemax.c - return size of maximum unallocated heap block
4 Copyright (C) 2005, Vangelis Rokas <vrokas at otenet.gr>
6 Modifications for PIC14 by
7 Copyright (C) 2019 Gonzalo Pérez de Olaguer Córdoba <salo@gpoc.es>
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option) any
12 later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this library; see the file COPYING. If not, write to the
21 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 MA 02110-1301, USA.
24 As a special exception, if you link this library with other files,
25 some of which are compiled with SDCC, to produce an executable,
26 this library does not by itself cause the resulting executable to
27 be covered by the GNU General Public License. This exception does
28 not however invalidate any other reasons why the executable file
29 might be covered by the GNU General Public License.
30 -------------------------------------------------------------------------*/
32 #include <pic14_malloc.h>
34 size_t memfreemax (void)
36 _malloc_rec __data *head;
37 size_t size = 1;
38 size_t len;
40 if (_malloc_heap == NULL)
41 return 0;
43 head = _malloc_heap;
45 while ((len = head->bits.count) != 0)
47 if (!head->bits.alloc && (len > size))
48 size = len;
50 head = NEXTREC(head);
53 /* do not count the block header */
54 return size - 1;