summary refs log tree commit diff
path: root/src/daemontools-extras/s6-tai64n.c
blob: 085c053f8d80fd27b6f0d512db1c659197d786f8 (plain) (blame)
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
/* ISC license. */

#include <errno.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
#include <skalibs/tai.h>
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>

int main (void)
{
  char stamp[TIMESTAMP+1] ;
  PROG = "s6-tai64n" ;
  stamp[TIMESTAMP] = ' ' ;
  for (;;)
  {
    register int r = skagetln(buffer_0f1, &satmp, '\n') ;
    if (r < 0)
      if (errno != EPIPE)
        strerr_diefu1sys(111, "read from stdin") ;
      else
      {
        r = 1 ;
        if (!stralloc_catb(&satmp, "\n", 1))
          strerr_diefu1sys(111, "add newline") ;
      }
    else if (!r) break ;
    timestamp(stamp) ;
    if ((buffer_put(buffer_1, stamp, TIMESTAMP+1) < 0)
     || (buffer_put(buffer_1, satmp.s, satmp.len) < 0))
      strerr_diefu1sys(111, "write to stdout") ;
    satmp.len = 0 ;
  }
  return 0 ;
}