wmii/libcext/evector.c

33 lines
642 B
C
Raw Normal View History

2006-04-03 00:56:25 +04:00
/* extendible vectors. Icarus Sparry 2006. Public domain. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2006-04-03 00:56:25 +04:00
#include <unistd.h>
#include "cext.h"
void
cext_evector_attach(evector_t *v, void *p)
{
++v->size;
if (!(v->data = realloc(v->data, v->size * sizeof(void *)))) {
fprintf(stderr, "%s\n", "Out of memory in cext_evector_attach\n");
exit(1);
2006-04-03 00:56:25 +04:00
}
v->data[v->size - 1]=p;
2006-04-03 00:56:25 +04:00
}
void
cext_evector_detach(evector_t *v, void *data)
{
void **p = v->data, **end;
if (!p) return;
for(end = p + v->size - 1; p <= end; p++)
2006-04-03 00:56:25 +04:00
if (*p == data) {
memmove(p, p + 1, end - (p + 1));
2006-04-03 00:56:25 +04:00
*end = nil;
--v->size;
return;
}
}