xref: /minix3/external/bsd/flex/dist/lib/realloc.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*84d9c625SLionel Sambuc #include <config.h>
2*84d9c625SLionel Sambuc 
3*84d9c625SLionel Sambuc #include <stdlib.h>
4*84d9c625SLionel Sambuc 
5*84d9c625SLionel Sambuc #include <errno.h>
6*84d9c625SLionel Sambuc 
rpl_realloc(void * p,size_t n)7*84d9c625SLionel Sambuc void * rpl_realloc (void *p, size_t n)
8*84d9c625SLionel Sambuc {
9*84d9c625SLionel Sambuc   void *result;
10*84d9c625SLionel Sambuc 
11*84d9c625SLionel Sambuc   if (n == 0)
12*84d9c625SLionel Sambuc     {
13*84d9c625SLionel Sambuc       n = 1;
14*84d9c625SLionel Sambuc     }
15*84d9c625SLionel Sambuc 
16*84d9c625SLionel Sambuc   if (p == NULL)
17*84d9c625SLionel Sambuc     {
18*84d9c625SLionel Sambuc       result = malloc (n);
19*84d9c625SLionel Sambuc     }
20*84d9c625SLionel Sambuc   else
21*84d9c625SLionel Sambuc     result = realloc (p, n);
22*84d9c625SLionel Sambuc 
23*84d9c625SLionel Sambuc   if (result == NULL)
24*84d9c625SLionel Sambuc     errno = ENOMEM;
25*84d9c625SLionel Sambuc 
26*84d9c625SLionel Sambuc   return result;
27*84d9c625SLionel Sambuc }
28