Fix #1877: use dprintf() instead of write()

This commit is contained in:
Arun Prakash Jana 2024-05-06 19:05:46 +05:30
parent be6988d1c8
commit 55137600e0
No known key found for this signature in database
GPG key ID: 4A865183AF6C5631

View file

@ -5197,25 +5197,21 @@ static void show_help(const char *path)
get_output(prog, NULL, NULL, fd, FALSE); get_output(prog, NULL, NULL, fd, FALSE);
bool hex = true; bool hex = true;
const char space = ' '; const char *end = helpstr + sizeof(helpstr) - 1;
const char *end = helpstr + (sizeof helpstr - 1);
for (const char *s = helpstr; s < end; ++s) { for (const char *s = helpstr; s < end; ++s) {
if (hex) { if (hex) {
for (int k = 0, n = xchartohex(*s); k < n; ++k) for (int k = 0, n = xchartohex(*s); k < n; ++k)
if (write(fd, &space, 1) != 1) dprintf(fd, " ");
break;
} else if (*s == '%') { } else if (*s == '%') {
int n = ((s[1] - '0') * 10) + (s[2] - '0'); int n = ((s[1] - '0') * 10) + (s[2] - '0');
for (int k = 0; k < n; ++k) for (int k = 0; k < n; ++k)
if (write(fd, &space, 1) != 1) dprintf(fd, " ");
break;
s += 2; s += 2;
} else { } else {
if (write(fd, s, 1) != 1) dprintf(fd, "%c", *s);
break;
} }
hex = *s == '\n'; hex = (*s == '\n');
} }
dprintf(fd, "\nLOCATIONS\n"); dprintf(fd, "\nLOCATIONS\n");