Commit | Line | Data |
---|---|---|
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 | ||
9 | static substdio ss; | |
10 | static char buf[1]; | |
11 | static char num[FMT_ULONG]; | |
12 | static stralloc line = {0}; | |
13 | ||
14 | void log(event,addr) | |
15 | char *event; | |
16 | char *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 | } |