summaryrefslogtreecommitdiff
path: root/src/predate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/predate.c')
-rw-r--r--src/predate.c83
1 files changed, 39 insertions, 44 deletions
diff --git a/src/predate.c b/src/predate.c
index f6007b3..6512d20 100644
--- a/src/predate.c
+++ b/src/predate.c
@@ -1,20 +1,22 @@
#include <sys/types.h>
-#include <time.h>
#include <unistd.h>
-#include "datetime.h"
-#include "wait.h"
+
+#include <time.h>
+
+#include "buffer.h"
+#include "exit.h"
#include "fd.h"
#include "fmt.h"
#include "logmsg.h"
-#include "buffer.h"
-#include "exit.h"
#include "sig.h"
+#include "wait.h"
+
+#include "datetime.h"
#define WHO "predate"
static char *montab[12] = {
-"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
-};
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char num[FMT_ULONG];
char outbuf[1024];
@@ -34,25 +36,21 @@ int main(int argc, char **argv)
sig_pipeignore();
- if (!argv[1])
- logmsg(WHO,100,USAGE,"predate child");
+ if (!argv[1]) logmsg(WHO, 100, USAGE, "predate child");
- if (pipe(pi) == -1)
- logmsg(WHO,111,FATAL,"unable to create pipe");
+ if (pipe(pi) == -1) logmsg(WHO, 111, FATAL, "unable to create pipe");
switch (pid = fork()) {
- case -1:
- logmsg(WHO,111,FATAL,"unable to fork");
+ case -1: logmsg(WHO, 111, FATAL, "unable to fork");
case 0:
close(pi[1]);
- if (fd_move(0,pi[0]) == -1)
- logmsg(WHO,111,FATAL,"unable to set up fds");
+ if (fd_move(0, pi[0]) == -1) logmsg(WHO, 111, FATAL, "unable to set up fds");
sig_pipedefault();
- execvp(argv[1],argv + 1);
- logmsg(WHO,111,FATAL,B("unable to run: ",argv[1]));
+ execvp(argv[1], argv + 1);
+ logmsg(WHO, 111, FATAL, B("unable to run: ", argv[1]));
}
close(pi[0]);
- buffer_init(&bo,write,pi[1],outbuf,sizeof(outbuf));
+ buffer_init(&bo, write, pi[1], outbuf, sizeof(outbuf));
time(&now);
@@ -74,40 +72,37 @@ int main(int argc, char **argv)
dt.sec = tm->tm_sec;
local = datetime_untai(&dt);
- buffer_puts(&bo,"Date: ");
- buffer_put(&bo,num,fmt_uint(num,dt.mday));
- buffer_puts(&bo," ");
- buffer_puts(&bo,montab[dt.mon]);
- buffer_puts(&bo," ");
- buffer_put(&bo,num,fmt_uint(num,dt.year + 1900));
- buffer_puts(&bo," ");
- buffer_put(&bo,num,fmt_uint0(num,dt.hour,2));
- buffer_puts(&bo,":");
- buffer_put(&bo,num,fmt_uint0(num,dt.min,2));
- buffer_puts(&bo,":");
- buffer_put(&bo,num,fmt_uint0(num,dt.sec,2));
+ buffer_puts(&bo, "Date: ");
+ buffer_put(&bo, num, fmt_uint(num, dt.mday));
+ buffer_puts(&bo, " ");
+ buffer_puts(&bo, montab[dt.mon]);
+ buffer_puts(&bo, " ");
+ buffer_put(&bo, num, fmt_uint(num, dt.year + 1900));
+ buffer_puts(&bo, " ");
+ buffer_put(&bo, num, fmt_uint0(num, dt.hour, 2));
+ buffer_puts(&bo, ":");
+ buffer_put(&bo, num, fmt_uint0(num, dt.min, 2));
+ buffer_puts(&bo, ":");
+ buffer_put(&bo, num, fmt_uint0(num, dt.sec, 2));
if (local < utc) {
minutes = (utc - local + 30) / 60;
- buffer_puts(&bo," -");
- buffer_put(&bo,num,fmt_uint0(num,minutes / 60,2));
- buffer_put(&bo,num,fmt_uint0(num,minutes % 60,2));
- }
- else {
+ buffer_puts(&bo, " -");
+ buffer_put(&bo, num, fmt_uint0(num, minutes / 60, 2));
+ buffer_put(&bo, num, fmt_uint0(num, minutes % 60, 2));
+ } else {
minutes = (local - utc + 30) / 60;
- buffer_puts(&bo," +");
- buffer_put(&bo,num,fmt_uint0(num,minutes / 60,2));
- buffer_put(&bo,num,fmt_uint0(num,minutes % 60,2));
+ buffer_puts(&bo, " +");
+ buffer_put(&bo, num, fmt_uint0(num, minutes / 60, 2));
+ buffer_put(&bo, num, fmt_uint0(num, minutes % 60, 2));
}
- buffer_puts(&bo,"\n");
- buffer_copy(&bo,buffer_0);
+ buffer_puts(&bo, "\n");
+ buffer_copy(&bo, buffer_0);
buffer_flush(&bo);
close(pi[1]);
- if (wait_pid(&wstat,pid) == -1)
- logmsg(WHO,111,FATAL,"wait failed");
- if (wait_crashed(wstat))
- logmsg(WHO,111,FATAL,"child crashed");
+ if (wait_pid(&wstat, pid) == -1) logmsg(WHO, 111, FATAL, "wait failed");
+ if (wait_crashed(wstat)) logmsg(WHO, 111, FATAL, "child crashed");
_exit(wait_exitcode(wstat));
}