9 /* appends (not crash-proof) a line to "Log". The format is: */
10 /* "timestamp event address[ comment]\n". address is free of ' ' */
11 /* Unprintable chars are changed to '?'. Comment may have spaces */
15 static char num[FMT_ULONG];
16 static stralloc line = {0};
17 static stralloc fn = {0};
19 void log(dir,event,addr,comment)
28 if (!stralloc_copyb(&line,num,fmt_ulong(num,(unsigned long) now()))) return;
29 if (!stralloc_cats(&line," ")) return;
30 if (!stralloc_cats(&line,event)) return;
31 if (!stralloc_cats(&line," ")) return;
32 while (ch = *addr++) {
33 if ((ch < 33) || (ch > 126)) ch = '?';
34 if (!stralloc_append(&line,&ch)) return;
36 if (comment && *comment) {
37 if (!stralloc_cats(&line," ")) return;
38 while (ch = *comment++) {
42 if ((ch < 32) || (ch > 126)) ch = '?';
43 if (!stralloc_append(&line,&ch)) return;
46 if (!stralloc_cats(&line,"\n")) return;
48 if (!stralloc_copys(&fn,dir)) return;
49 if (!stralloc_cats(&fn,"/Log")) return;
50 if (!stralloc_0(&fn)) return;
51 fd = open_append(fn.s);
53 substdio_fdbuf(&ss,write,fd,buf,sizeof(buf));
54 substdio_putflush(&ss,line.s,line.len);