diff cutils.c @ 151:ec4d9190d3b1 libavformat

dynamic array functions
author bellard
date Fri, 13 Jun 2003 14:22:23 +0000
parents b0e0eb595e29
children b0771ae979e3
line wrap: on
line diff
--- a/cutils.c	Mon Jun 09 19:11:50 2003 +0000
+++ b/cutils.c	Fri Jun 13 14:22:23 2003 +0000
@@ -108,3 +108,24 @@
 }
 
 #endif
+
+/* add one element to a dynamic array */
+void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
+{
+    int nb, nb_alloc;
+    unsigned long *tab;
+
+    nb = *nb_ptr;
+    tab = *tab_ptr;
+    if ((nb & (nb - 1)) == 0) {
+        if (nb == 0)
+            nb_alloc = 1;
+        else
+            nb_alloc = nb * 2;
+        tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
+        *tab_ptr = tab;
+    }
+    tab[nb++] = elem;
+    *nb_ptr = nb;
+}
+