s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
tai64nfrac.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "stralloc.h"
3#include "exit.h"
4#include "readwrite.h"
5#include "open.h"
6#include "scan.h"
7#include "fmt.h"
8#include "getln.h"
9
10#define TAI64NLEN 24
11
18char outbuf[64];
19buffer bo = BUFFER_INIT(write,1,outbuf,sizeof(outbuf));
20
21static void outs(char *s)
22{
23 if (buffer_puts(&bo,s) == -1) _exit(1);
24 if (buffer_flush(&bo) == -1) _exit(1);
25}
26
27static void outi(int i)
28{
29 char num[FMT_ULONG];
30
31 if (buffer_put(&bo,num,fmt_ulong(num,(unsigned long) i)) == -1) _exit(1);
32 if (buffer_flush(&bo) == -1) _exit(1);
33}
34
35char inbuf[1024];
36buffer bi = BUFFER_INIT(read,0,inbuf,sizeof(inbuf));
37
38int main(void)
39{
40 int c;
41 int i;
42 int match;
43 unsigned long u;
44 unsigned long seconds;
45 unsigned long nanoseconds;
46 stralloc line = {0};
47
48/* Read from stdin */
49
50 buffer_init(&bi,read,0,inbuf,sizeof(inbuf));
51
52 for (;;) {
53 if (getln(&bi,&line,&match,'\n') != 0) _exit(1);
54 if (!match) break;
55 if (!stralloc_0(&line)) _exit(1);
56
57 seconds = 0;
58 nanoseconds = 0;
59
60 if (line.s[0] == '@') { /* tai64 timestamp */
61 for (i = 1; i <= TAI64NLEN; i++) {
62 c = (int)line.s[i];
63 u = c - '0';
64 if (u >= 10) {
65 u = c - 'a';
66 if (u >= 6) break;
67 u += 10;
68 }
69 seconds <<= 4;
70 seconds += nanoseconds >> 28;
71 nanoseconds &= 0xfffffff;
72 nanoseconds <<= 4;
73 nanoseconds += u;
74 }
75 seconds -= 4611686018427387914ULL;
76 seconds = seconds > 0 ? seconds : 0;
77 outi(seconds); outs("."); outi(nanoseconds); outs(line.s + i); outs("\n");
78 } else {
79 outs("tai64nfrac: fatal: Wrong TAI64N input format."); outs("\n");
80 _exit(1);
81 }
82 }
83
84 _exit(0);
85}
void outs(char *s)
Definition: auto-gid.c:12
char num[FMT_ULONG]
Definition: chkspawn.c:8
void _exit()
void c(char *, char *, char *, int, int, int)
Definition: install.c:57
stralloc line
Definition: maildir2mbox.c:27
int match
Definition: matchup.c:195
int
Definition: qmail-mrtg.c:26
char inbuf[1024]
Definition: tai64nfrac.c:35
#define TAI64NLEN
Definition: tai64nfrac.c:10
int main(void)
Definition: tai64nfrac.c:38
char outbuf[64]
Definition: tai64nfrac.c:18
buffer bi
Definition: tai64nfrac.c:36
buffer bo
Definition: tai64nfrac.c:19
void write()