diff --git a/bootstrap.conf b/bootstrap.conf index 8c2265f..70bced4 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -156,9 +156,12 @@ gnulib_modules=" manywarnings mbrlen mbrtowc + mbrtowc-factory mbsalign mbschr + mbsinit-factory mbslen + mbsreset-factory mbswidth memcasecmp memchr @@ -273,6 +276,7 @@ gnulib_modules=" version-etc-fsf wcswidth wcwidth + wcwidth-factory winsz-ioctl winsz-termios write-any-file diff --git a/src/wc.c b/src/wc.c index 0c72042..daf596a 100644 --- a/src/wc.c +++ b/src/wc.c @@ -197,6 +199,13 @@ write_counts (uintmax_t lines, static bool wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) { + mbsreset_func_t mbsreset = get_optimized_mbsreset (); +#undef mbsinit + mbsinit_func_t mbsinit = get_optimized_mbsinit (); +#undef mbrtowc + mbrtowc_func_t mbrtowc = get_optimized_mbrtowc (); +#undef wcwidth + wcwidth_func_t wcwidth = get_optimized_wcwidth (); bool ok = true; char buf[BUFFER_SIZE + 1]; size_t bytes_read; @@ -344,7 +353,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) { bool in_word = false; uintmax_t linepos = 0; - mbstate_t state = { 0, }; + mbstate_t state; bool in_shift = false; # if SUPPORT_OLD_MBRTOWC /* Back-up the state before each multibyte character conversion and @@ -359,6 +368,8 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) const size_t prev = 0; # endif + mbsreset (&state); + while ((bytes_read = safe_read (fd, buf + prev, BUFFER_SIZE - prev)) > 0) { const char *p;