-void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
- int serv, const char *fmt, va_list al) {
- if (!(ads->iflags & adns_if_debug) && (!prevent || (ads->iflags & prevent))) return;
- if (serv>=0) {
- fprintf(stderr,"adns%s: nameserver %s: ",pfx,inet_ntoa(ads->servers[serv].addr));
- } else {
- fprintf(stderr,"adns%s: ",pfx);
- }
- vfprintf(stderr,fmt,al);
- fputc('\n',stderr);
-}
-
-void adns__debug(adns_state ads, int serv, const char *fmt, ...) {
- va_list al;
-
- va_start(al,fmt);
- adns__vdiag(ads," debug",0,serv,fmt,al);
- va_end(al);
-}
-
-void adns__warn(adns_state ads, int serv, const char *fmt, ...) {
- va_list al;
-
- va_start(al,fmt);
- adns__vdiag(ads," warning",adns_if_noerrprint|adns_if_noserverwarn,serv,fmt,al);
- va_end(al);
-}
-
-void adns__diag(adns_state ads, int serv, const char *fmt, ...) {
- va_list al;
-
- va_start(al,fmt);
- adns__vdiag(ads,"",adns_if_noerrprint,serv,fmt,al);
- va_end(al);
-}
-
-
-void adns__vbuf_init(vbuf *vb) {
- vb->used= vb->avail= 0; vb->buf= 0;
-}
-
-int adns__vbuf_ensure(vbuf *vb, int want) {
- void *nb;
-
- if (vb->avail >= want) return 1;
- nb= realloc(vb->buf,want); if (!nb) return 0;
- vb->buf= nb;
- vb->avail= want;
- return 1;
-}
-
-void adns__vbuf_appendq(vbuf *vb, const byte *data, int len) {
- memcpy(vb->buf+vb->used,data,len);
- vb->used+= len;
-}
-
-int adns__vbuf_append(vbuf *vb, const byte *data, int len) {
- int newlen;
- void *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;
-}
-
-