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