11 #include "readwrite.h"
14 #define FATAL "predate: fatal: "
16 static char *montab[12] = {
17 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
41 strerr_die1x(100,"predate: usage: predate child");
44 strerr_die2sys(111,FATAL,"unable to create pipe: ");
46 switch(pid = fork()) {
48 strerr_die2sys(111,FATAL,"unable to fork: ");
51 if (fd_move(0,pi[0]) == -1)
52 strerr_die2sys(111,FATAL,"unable to set up fds: ");
54 execvp(argv[1],argv + 1);
55 strerr_die4sys(111,FATAL,"unable to run ",argv[1],": ");
58 substdio_fdbuf(&ss,write,pi[1],outbuf,sizeof(outbuf));
63 dt.year = tm->tm_year;
65 dt.mday = tm->tm_mday;
66 dt.hour = tm->tm_hour;
69 utc = datetime_untai(&dt); /* utc == now, if gmtime ignores leap seconds */
72 dt.year = tm->tm_year;
74 dt.mday = tm->tm_mday;
75 dt.hour = tm->tm_hour;
78 local = datetime_untai(&dt);
80 substdio_puts(&ss,"Date: ");
81 substdio_put(&ss,num,fmt_uint(num,dt.mday));
82 substdio_puts(&ss," ");
83 substdio_puts(&ss,montab[dt.mon]);
84 substdio_puts(&ss," ");
85 substdio_put(&ss,num,fmt_uint(num,dt.year + 1900));
86 substdio_puts(&ss," ");
87 substdio_put(&ss,num,fmt_uint0(num,dt.hour,2));
88 substdio_puts(&ss,":");
89 substdio_put(&ss,num,fmt_uint0(num,dt.min,2));
90 substdio_puts(&ss,":");
91 substdio_put(&ss,num,fmt_uint0(num,dt.sec,2));
94 minutes = (utc - local + 30) / 60;
95 substdio_puts(&ss," -");
96 substdio_put(&ss,num,fmt_uint0(num,minutes / 60,2));
97 substdio_put(&ss,num,fmt_uint0(num,minutes % 60,2));
100 minutes = (local - utc + 30) / 60;
101 substdio_puts(&ss," +");
102 substdio_put(&ss,num,fmt_uint0(num,minutes / 60,2));
103 substdio_put(&ss,num,fmt_uint0(num,minutes % 60,2));
106 substdio_puts(&ss,"\n");
107 substdio_copy(&ss,subfdin);
111 if (wait_pid(&wstat,pid) == -1)
112 strerr_die2sys(111,FATAL,"wait failed: ");
113 if (wait_crashed(wstat))
114 strerr_die2x(111,FATAL,"child crashed");
115 _exit(wait_exitcode(wstat));