Import ezmlm 0.53
[ezmlm] / log.c
CommitLineData
5b62e993
MW
1#include "substdio.h"
2#include "readwrite.h"
3#include "stralloc.h"
4#include "log.h"
5#include "now.h"
6#include "fmt.h"
7#include "open.h"
8
9static substdio ss;
10static char buf[1];
11static char num[FMT_ULONG];
12static stralloc line = {0};
13
14void log(event,addr)
15char *event;
16char *addr;
17{
18 char ch;
19 int fd;
20
21 if (!stralloc_copyb(&line,num,fmt_ulong(num,(unsigned long) now()))) return;
22 if (!stralloc_cats(&line," ")) return;
23 if (!stralloc_cats(&line,event)) return;
24 if (!stralloc_cats(&line," ")) return;
25 while (ch = *addr++) {
26 if ((ch < 33) || (ch > 126)) ch = '?';
27 if (!stralloc_append(&line,&ch)) return;
28 }
29 if (!stralloc_cats(&line,"\n")) return;
30
31 fd = open_append("Log");
32 if (fd == -1) return;
33 substdio_fdbuf(&ss,write,fd,buf,sizeof(buf));
34 substdio_putflush(&ss,line.s,line.len);
35 close(fd);
36 return;
37}