fix regressions
[apps/madmutt.git] / lib / mem.c
1 /*
2  * This file is part of mutt-ng, see http://www.muttng.org/.
3  * It's licensed under the GNU General Public License,
4  * please see the file GPL in the top level source directory.
5  */
6
7 #include <stdlib.h>
8
9 #include "mem.h"
10 #include "exit.h"
11 #include "intl.h"
12
13 void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
14   void *r;
15   void **p = (void **) ptr;
16
17   if (siz == 0) {
18     if (*p) {
19       free (*p);                /* __MEM_CHECKED__ */
20       *p = NULL;
21     }
22     return;
23   }
24
25   if (*p)
26     r = (void *) realloc (*p, siz);     /* __MEM_CHECKED__ */
27   else {
28     /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x  --- __MEM_CHECKED__ */
29     r = (void *) malloc (siz);  /* __MEM_CHECKED__ */
30   }
31
32   if (!r)
33     exit_fatal ("mem_realloc", _("Out of memory!"), line, fname, 1);
34
35   *p = r;
36 }