gensetdyn_ready.c (658B)
1 /* ISC license. */ 2 3 #include <skalibs/stralloc.h> 4 #include <skalibs/genalloc.h> 5 #include <skalibs/gensetdyn.h> 6 7 int gensetdyn_ready (gensetdyn *g, uint32_t n) 8 { 9 int wasnull = !g->storage.s ; 10 uint32_t i = g->storage.len ; 11 if (n < i) return 1 ; 12 n += g->base + (n * g->fracnum) / g->fracden ; 13 if (!stralloc_ready_tuned(&g->storage, n * g->esize, 0, 0, 1)) return 0 ; 14 if (!genalloc_ready(uint32_t, &g->freelist, n)) 15 { 16 if (wasnull) stralloc_free(&g->storage) ; 17 return 0 ; 18 } 19 for (; i < n ; i++) 20 { 21 uint32_t j = n - 1 - i + g->storage.len ; 22 genalloc_catb(uint32_t, &g->freelist, &j, 1) ; 23 } 24 g->storage.len = n ; 25 return 1 ; 26 }