summaryrefslogtreecommitdiff
path: root/src/skaembutils/s6-echo.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
commitbea0037dbdd979603fb0b5be8b43f5478c1f6fec (patch)
tree5776ae3af5a3e83d41c7087f70713952b6360988 /src/skaembutils/s6-echo.c
downloads6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.xz
initial commit
Diffstat (limited to 'src/skaembutils/s6-echo.c')
-rw-r--r--src/skaembutils/s6-echo.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/skaembutils/s6-echo.c b/src/skaembutils/s6-echo.c
new file mode 100644
index 0000000..6d30576
--- /dev/null
+++ b/src/skaembutils/s6-echo.c
@@ -0,0 +1,38 @@
+/* ISC license. */
+
+#include <skalibs/sgetopt.h>
+#include <skalibs/buffer.h>
+#include <skalibs/strerr2.h>
+
+#define USAGE "s6-echo [ -n ] [ -s sep ] args..."
+
+int main (int argc, char const *const *argv)
+{
+ char sep = ' ' ;
+ char donl = 1 ;
+ PROG = "s6-echo" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ register 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) == -1)))
+ goto err ;
+ if (donl && (buffer_put(buffer_1small, "\n", 1) == -1)) goto err ;
+ if (!buffer_flush(buffer_1small)) goto err ;
+ return 0 ;
+err:
+ strerr_diefu1sys(111, "write to stdout") ;
+}