summaryrefslogtreecommitdiff
path: root/src/clients/s6-dnstxt.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-07-12 16:53:59 +0000
committerLaurent Bercot <ska@appnovation.com>2023-07-12 16:53:59 +0000
commit207845f50a8fb54fe8e584928078dc3687399caf (patch)
treef58eac67edc2dbaba13a48442a2093f76e869991 /src/clients/s6-dnstxt.c
parent8cf671e973a4ea2ef7c9ca1321531a7ceeaa5073 (diff)
downloads6-dns-207845f50a8fb54fe8e584928078dc3687399caf.tar.xz
Pass on all clients, add hosts support wherever applicable
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/clients/s6-dnstxt.c')
-rw-r--r--src/clients/s6-dnstxt.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/clients/s6-dnstxt.c b/src/clients/s6-dnstxt.c
index 2564917..5818ac8 100644
--- a/src/clients/s6-dnstxt.c
+++ b/src/clients/s6-dnstxt.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -11,6 +12,7 @@
#include <skalibs/genalloc.h>
#include <skalibs/skamisc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnstxt [ -q ] [ -r ] [ -t timeout ] name"
@@ -23,24 +25,27 @@ int main (int argc, char const *const *argv)
genalloc offsets = GENALLOC_ZERO ; /* array of size_t */
tain deadline ;
size_t n ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
int flagunsort = 0 ;
PROG = "s6-dnstxt" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
@@ -56,7 +61,7 @@ int main (int argc, char const *const *argv)
if (!n) return 1 ;
{
size_t printable_offsets[n] ;
- for (i = 0 ; i < n ; i++)
+ for (size_t i = 0 ; i < n ; i++)
{
size_t beg = genalloc_s(size_t, &offsets)[i] ;
size_t end = (i < n-1 ? genalloc_s(size_t, &offsets)[i+1] : sa.len) - 1 ;
@@ -67,7 +72,7 @@ int main (int argc, char const *const *argv)
genalloc_free(size_t, &offsets) ;
stralloc_free(&sa) ;
if (flagunsort) random_unsort((char *)printable_offsets, n, sizeof(size_t)) ;
- for (i = 0 ; i < n ; i++)
+ for (size_t i = 0 ; i < n ; i++)
if ((buffer_puts(buffer_1small, quoted.s + printable_offsets[i]) < 0)
|| (buffer_put(buffer_1small, "\n", 1) < 1))
strerr_diefu1sys(111, "write to stdout") ;