Fliping a string in memory, and printing it with multibyte output
function makes the command about 1/3 quicker.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
+static void reverse_str(wchar_t *str, size_t n)
+{
+ size_t i;
+
+ for (i = 0; i < n / 2; ++i) {
+ wchar_t tmp = str[i];
+ str[i] = str[n - 1 - i];
+ str[n - 1 - i] = tmp;
+ }
+}
+
int main(int argc, char *argv[])
{
char *filename = "stdin";
- wchar_t *t;
size_t len, bufsiz = BUFSIZ;
FILE *fp = stdin;
int ch, rval = EXIT_SUCCESS;
len = wcslen(buf);
}
-
- if (*(t = buf + len - 1) == '\n')
- --t;
- for ( ; buf <= t; --t)
- putwchar(*t);
- if (!feof(fp))
- putwchar('\n');
+ reverse_str(buf, len - 1);
+ fputws(buf, stdout);
}
if (ferror(fp)) {
warn("%s", filename);