mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-25 08:42:39 +00:00
dynamic array functions
Originally committed as revision 1955 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
124ba5836f
commit
39f472c3b6
@ -428,6 +428,16 @@ int stristart(const char *str, const char *val, const char **ptr);
|
|||||||
void pstrcpy(char *buf, int buf_size, const char *str);
|
void pstrcpy(char *buf, int buf_size, const char *str);
|
||||||
char *pstrcat(char *buf, int buf_size, const char *s);
|
char *pstrcat(char *buf, int buf_size, const char *s);
|
||||||
|
|
||||||
|
void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
|
||||||
|
|
||||||
|
#define dynarray_add(tab, nb_ptr, elem)\
|
||||||
|
do {\
|
||||||
|
typeof(tab) _tab = (tab);\
|
||||||
|
typeof(elem) _elem = (elem);\
|
||||||
|
(void)sizeof(**_tab == _elem); /* check that types are compatible */\
|
||||||
|
__dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
|
||||||
|
} while(0)
|
||||||
|
|
||||||
struct in_addr;
|
struct in_addr;
|
||||||
int resolve_host(struct in_addr *sin_addr, const char *hostname);
|
int resolve_host(struct in_addr *sin_addr, const char *hostname);
|
||||||
|
|
||||||
|
@ -108,3 +108,24 @@ char *pstrcat(char *buf, int buf_size, const char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user