commit aaf9ec62504a6c8f52ad021b3d6c19aba1859977
parent 03cb248e711a127a5804e797c74c699c9ae2206b
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Sun, 2 Apr 2006 22:56:25 +0200
added evector.c
Diffstat:
1 file changed, 33 insertions(+), 0 deletions(-)
diff --git a/libcext/evector.c b/libcext/evector.c
@@ -0,0 +1,33 @@
+/* extendible vectors. Icarus Sparry 2006. Public domain. */
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "cext.h"
+
+#define ERRMSG "Out of memory in cext_evector_attach\n"
+void
+cext_evector_attach(evector_t *v, void *p)
+{
+ ++v->size;
+ if (!(v->data = realloc(v->data, v->size * sizeof(void *)))) {
+ write(2,ERRMSG,sizeof(ERRMSG)-1);
+ exit(99);
+ }
+ v->data[v->size-1]=p;
+}
+
+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++)
+ if (*p == data) {
+ for(; p<end; p++)
+ p[0] = p[1]; /* Could use memmove rather than this loop */
+ *end = nil;
+ --v->size;
+ return;
+ }
+}
+