blob: a59eae7903a9de5cb89953f7a19d06b6e012f684 (
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
32
33
34
35
36
37
38
39
|
/* ISC license. */
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
#define USAGE "s6-linux-init-echo [ -n ] [ -s sep ] args..."
int main (int argc, char const *const *argv)
{
char sep = ' ' ;
char donl = 1 ;
PROG = "s6-linux-init-echo" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = subgetopt_r(argc, argv, "ns:", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 'n': donl = 0 ; break ;
case 's': sep = *l.arg ; break ;
default : strerr_dieusage(100, USAGE) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
for ( ; *argv ; argv++)
if ((buffer_puts(buffer_1small, *argv) < 0)
|| (argv[1] && (buffer_put(buffer_1small, &sep, 1) < 0)))
goto err ;
if (donl && (buffer_put(buffer_1small, "\n", 1) < 0)) goto err ;
if (!buffer_flush(buffer_1small)) goto err ;
return 0 ;
err:
strerr_diefu1sys(111, "write to stdout") ;
}
|