File: o2_dynamic.c

package info (click to toggle)
o2 1.0~repack-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,156 kB
  • sloc: ansic: 9,132; python: 137; sh: 111; makefile: 10
file content (16 lines) | stat: -rw-r--r-- 463 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* o2_dynamic.c -- generic dynamic arrays */
#include "assert.h"
#include "o2.h"
#include "string.h"
#include "o2_dynamic.h"

void o2_da_expand(dyn_array_ptr array, int siz)
{
    if (array->allocated > 0) array->allocated *= 2;
    else array->allocated = 1;
    void *bigger = O2_MALLOC(array->allocated * siz);
    assert(bigger);
    memcpy(bigger, array->array, array->length * siz);
    if (array->array) O2_FREE(array->array);
    array->array = bigger;
}