1 #define _POSIX_C_SOURCE 200809L
11 #define ERR(str) { perror(str); err = EXIT_FAILURE; break; }
15 if (setlocale(LC_ALL, "") == NULL) {
23 int err = EXIT_SUCCESS;
25 while ((slen = getline(&ptr, &siz, stdin)) > 0) {
28 size_t len = mbstowcs(NULL, ptr, 0);
29 if (len == (size_t) -1) ERR("msbtowcs")
31 wchar_t *wcs = calloc(len + 1, sizeof *wcs);
32 if (!wcs) ERR("calloc")
34 if (mbstowcs(wcs, ptr, len + 1) == (size_t) -1) ERR("msbtowcs")
37 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) ERR("ioctl")
39 int trm_width = ws.ws_col;
40 int str_width = wcswidth(wcs, len);
44 for (int i = (trm_width - str_width) / 2; i > 0; i--)