diff options
author | ian <ian> | 1998-10-04 14:52:08 +0000 |
---|---|---|
committer | ian <ian> | 1998-10-04 14:52:08 +0000 |
commit | ddfda8613e6fd8b49d8532a6d34d26df29add034 (patch) | |
tree | f4e047142e6807af0225414ecf8eb5674defc8cb /src/setup.c | |
parent | 4bec51a44bf61bca32e7b947f20b1e7d0f971b94 (diff) |
Event loop stuff complete ?
Diffstat (limited to 'src/setup.c')
-rw-r--r-- | src/setup.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/setup.c b/src/setup.c index d7d9892..f1c2145 100644 --- a/src/setup.c +++ b/src/setup.c @@ -38,6 +38,41 @@ void adns__diag(adns_state ads, int serv, const char *fmt, ...) { va_end(al); } +/* FIXME: unsigned char -> byte everywhere */ + + +int adns__vbuf_ensure(adns__vbuf *vb, size_t want) { + byte *nb; + + if (vb->avail >= want) return; + nb= realloc(vb->buf,want); if (!nb) return 0; + vb->buf= nb; + vb->avail= want; + return 1; +} + +void adns__vbuf_appendq(adns__vbuf *vb, const byte *data, size_t len) { + memcpy(vb->buf+vb->used,data,len); + vb->used+= len; +} + +int adns__vbuf_append(adns__vbuf *vb, const byte *data, size_t len) { + size_t newlen, newalloc; + byte *nb; + + newlen= vb->used+len; + if (vb->avail < newlen) { + newlen <<= 1; + nb= realloc(vb->buf,newlen); + if (!nb) { newlen >>= 1; nb= realloc(vb->buf,newlen); } + if (!nb) return 0; + vb->buf= nb; + vb->avail= newlen; + } + adns__vbuf_appendq(vb,data,len); + return 1; +} + static void addserver(adns_state ads, struct in_addr addr) { int i; struct server *ss; @@ -191,7 +226,6 @@ int adns_init(adns_state *ads_r, adns_initflags flags) { int r; ads= malloc(sizeof(*ads)); if (!ads) return errno; - ads->tosend.head= ads->tosend.tail= 0; ads->timew.head= ads->timew.tail= 0; ads->childw.head= ads->childw.tail= 0; ads->output.head= ads->output.tail= 0; |