10 #include "readwrite.h"
13 static char *montab[12] = {
14 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
38 substdio_putsflush(subfderr,"predate: usage: predate child\n");
43 substdio_putsflush(subfderr,"predate: fatal: unable to create pipe\n");
47 switch(pid = fork()) {
49 substdio_putsflush(subfderr,"predate: fatal: unable to fork\n");
53 if (fd_move(0,pi[0]) == -1) {
54 substdio_putsflush(subfderr,"predate: fatal: unable to set up fds\n");
58 execvp(argv[1],argv + 1);
59 substdio_putsflush(subfderr,"predate: fatal: unable to exec\n");
63 substdio_fdbuf(&ss,write,pi[1],outbuf,sizeof(outbuf));
68 dt.year = tm->tm_year;
70 dt.mday = tm->tm_mday;
71 dt.hour = tm->tm_hour;
74 utc = datetime_untai(&dt); /* utc == now, if gmtime ignores leap seconds */
77 dt.year = tm->tm_year;
79 dt.mday = tm->tm_mday;
80 dt.hour = tm->tm_hour;
83 local = datetime_untai(&dt);
85 substdio_puts(&ss,"Date: ");
86 substdio_put(&ss,num,fmt_uint(num,dt.mday));
87 substdio_puts(&ss," ");
88 substdio_puts(&ss,montab[dt.mon]);
89 substdio_puts(&ss," ");
90 substdio_put(&ss,num,fmt_uint(num,dt.year + 1900));
91 substdio_puts(&ss," ");
92 substdio_put(&ss,num,fmt_uint0(num,dt.hour,2));
93 substdio_puts(&ss,":");
94 substdio_put(&ss,num,fmt_uint0(num,dt.min,2));
95 substdio_puts(&ss,":");
96 substdio_put(&ss,num,fmt_uint0(num,dt.sec,2));
99 minutes = (utc - local + 30) / 60;
100 substdio_puts(&ss," -");
101 substdio_put(&ss,num,fmt_uint0(num,minutes / 60,2));
102 substdio_put(&ss,num,fmt_uint0(num,minutes % 60,2));
105 minutes = (local - utc + 30) / 60;
106 substdio_puts(&ss," +");
107 substdio_put(&ss,num,fmt_uint0(num,minutes / 60,2));
108 substdio_put(&ss,num,fmt_uint0(num,minutes % 60,2));
111 substdio_puts(&ss,"\n");
112 substdio_copy(&ss,subfdin);
116 if (wait_pid(&wstat,pid) == -1) {
117 substdio_putsflush(subfderr,"predate: fatal: wait failed\n");
120 if (wait_crashed(wstat)) {
121 substdio_putsflush(subfderr,"predate: fatal: child crashed\n");
124 _exit(wait_exitcode(wstat));