summaryrefslogtreecommitdiff
path: root/src/skadns/skadns_release.c
blob: 3ce2fc300f2a9d928a73ea032aef4da3e29c8a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ISC license. */

/* OpenBSD sucks */
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif

#include <stdint.h>
#include <errno.h>
#include <skalibs/alloc.h>
#include <skalibs/gensetdyn.h>
#include <s6-dns/skadns.h>

int skadns_release (skadns_t *a, uint16_t id)
{
  register skadnsanswer_t *p = GENSETDYN_P(skadnsanswer_t, &a->q, id) ;
  switch (p->status)
  {
    case 0 :
      alloc_free(p->data) ; p->data = 0 ; p->len = 0 ;
      break ;
    case EAGAIN :
    case ECANCELED :
      return (errno = EBUSY, 0) ;
    case EINVAL :
      return (errno = EINVAL, 0) ;
    default : break ;
  }
  p->status = EINVAL ;
  return gensetdyn_delete(&a->q, id) ;
}