(journal_entry): Print unprintable characters in octal instead of a question mark.
This commit is contained in:
parent
568ef6048d
commit
2cdfec6a3a
1 changed files with 13 additions and 9 deletions
|
@ -75,23 +75,27 @@ journal_entry(char *fmt, ...)
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
time_t now;
|
time_t now;
|
||||||
int n, i;
|
unsigned char *p;
|
||||||
|
|
||||||
if (journal) {
|
if (journal) {
|
||||||
time(&now);
|
time(&now);
|
||||||
n = sprintf(buf, "%.24s %p ", ctime(&now), empth_self());
|
fprintf(journal, "%.24s %p ", ctime(&now), empth_self());
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(buf + n, sizeof(buf) - n - 1, fmt, ap);
|
vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
for (i = n; buf[i]; ++i) {
|
for (p = buf; *p; p++) {
|
||||||
if (!isprint((unsigned char)buf[i]))
|
if (isprint(*p))
|
||||||
buf[i] = '?'; /* FIXME replace by escape */
|
putc(*p, journal);
|
||||||
|
else
|
||||||
|
fprintf(journal, "\\%03o", *p);
|
||||||
}
|
}
|
||||||
buf[i++] = '\n';
|
fputs("\n", journal);
|
||||||
buf[i] = 0;
|
if (ferror(journal)) {
|
||||||
if (fputs(buf, journal) == EOF)
|
|
||||||
logerror("Error writing journal (%s)", strerror(errno));
|
logerror("Error writing journal (%s)", strerror(errno));
|
||||||
|
clearerr(journal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue