blob: 7bcf4966ccffd05e12403a302c92289cfccfb0fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/*
* Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
* SPDX-License-Identifier: MIT
*/
#include <assert.h>
#include "ensize.h"
#include "eprintf.h"
// ensize: realloc p if it is smaller than count given current size
void *ensize(void *p, size_t selem, size_t nelem, size_t *cur, size_t init)
{
assert(cur != NULL);
if (*cur >= nelem * selem)
return p;
if (*cur == 0)
*cur = init * selem;
else
*cur *= 2;
return erealloc(p, *cur);
}
|