~ubuntu-branches/ubuntu/oneiric/daemontools/oneiric

« back to all changes in this revision

Viewing changes to daemontools-0.76/src/tai64nlocal.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2008-04-16 21:20:38 UTC
  • Revision ID: james.westby@ubuntu.com-20080416212038-2ix54o7w5m8lpvni
Tags: upstream-0.76
ImportĀ upstreamĀ versionĀ 0.76

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <sys/types.h>
 
2
#include <time.h>
 
3
#include <sys/time.h>
 
4
#include <unistd.h>
 
5
#include "buffer.h"
 
6
#include "fmt.h"
 
7
 
 
8
char num[FMT_ULONG];
 
9
 
 
10
void get(char *ch)
 
11
{
 
12
  int r;
 
13
 
 
14
  r = buffer_GETC(buffer_0,ch);
 
15
  if (r == 1) return;
 
16
  if (r == 0) _exit(0);
 
17
  _exit(111);
 
18
}
 
19
 
 
20
void out(const char *buf,int len)
 
21
{
 
22
  if (buffer_put(buffer_1,buf,len) == -1)
 
23
    _exit(111);
 
24
}
 
25
 
 
26
time_t secs;
 
27
unsigned long nanosecs;
 
28
unsigned long u;
 
29
struct tm *t;
 
30
 
 
31
int main()
 
32
{
 
33
  char ch;
 
34
 
 
35
  for (;;) {
 
36
    get(&ch);
 
37
    if (ch == '@') {
 
38
      secs = 0;
 
39
      nanosecs = 0;
 
40
      for (;;) {
 
41
        get(&ch);
 
42
        u = ch - '0';
 
43
        if (u >= 10) {
 
44
          u = ch - 'a';
 
45
          if (u >= 6) break;
 
46
          u += 10;
 
47
        }
 
48
        secs <<= 4;
 
49
        secs += nanosecs >> 28;
 
50
        nanosecs &= 0xfffffff;
 
51
        nanosecs <<= 4;
 
52
        nanosecs += u;
 
53
      }
 
54
      secs -= 4611686018427387914ULL;
 
55
      t = localtime(&secs);
 
56
      out(num,fmt_ulong(num,1900 + t->tm_year));
 
57
      out("-",1); out(num,fmt_uint0(num,1 + t->tm_mon,2));
 
58
      out("-",1); out(num,fmt_uint0(num,t->tm_mday,2));
 
59
      out(" ",1); out(num,fmt_uint0(num,t->tm_hour,2));
 
60
      out(":",1); out(num,fmt_uint0(num,t->tm_min,2));
 
61
      out(":",1); out(num,fmt_uint0(num,t->tm_sec,2));
 
62
      out(".",1); out(num,fmt_uint0(num,nanosecs,9));
 
63
    }
 
64
    for (;;) {
 
65
      out(&ch,1);
 
66
      if (ch == '\n') break;
 
67
      get(&ch);
 
68
    }
 
69
  }
 
70
}