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;
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;
proto= getprotobyname("udp"); if (!proto) { r= ENOPROTOOPT; goto x_free; }
ads->udpsocket= socket(AF_INET,SOCK_DGRAM,proto->p_proto);
- if (!ads->udpsocket) { r= errno; goto x_closeudp; }
+ if (ads->udpsocket<0) { r= errno; goto x_free; }
+
+ /*fixme: nonblock */
*ads_r= ads;
return 0;
- x_closeudp:
- close(ads->udpsocket);
x_free:
free(ads);
return r;