+ const char *s, *end = buf + len;
+ for (s = buf; s < end; s++) {
+ if ((s < end - 4
+ && *s == '\\' && s[1] == '0'
+ && isdigit(*(uchar*)(s+2))
+ && isdigit(*(uchar*)(s+3))
+ && isdigit(*(uchar*)(s+4)))
+ || !isprint(*(uchar*)s)
+ || *(uchar*)s < ' ') {
+ if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
+ exit_cleanup(RERR_MESSAGEIO);
+ fprintf(f, "\\%04o", *(uchar*)s);
+ buf = s + 1;
+ }