=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/uniq/uniq.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- src/usr.bin/uniq/uniq.c 2015/11/02 20:25:42 1.23 +++ src/usr.bin/uniq/uniq.c 2015/12/19 10:21:01 1.24 @@ -1,4 +1,4 @@ -/* $OpenBSD: uniq.c,v 1.23 2015/11/02 20:25:42 mmcc Exp $ */ +/* $OpenBSD: uniq.c,v 1.24 2015/12/19 10:21:01 schwarze Exp $ */ /* $NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $ */ /* @@ -37,10 +37,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #define MAXLINELEN (8 * 1024) @@ -61,6 +64,8 @@ int ch; char *prevline, *thisline; + setlocale(LC_CTYPE, ""); + if (pledge("stdio rpath wpath cpath", NULL) == -1) err(1, "pledge"); @@ -176,16 +181,32 @@ char * skip(char *str) { + wchar_t wc; int nchars, nfields; + int len; + int field_started; for (nfields = numfields; nfields && *str; nfields--) { - while (isblank((unsigned char)*str)) - str++; - while (*str && !isblank((unsigned char)*str)) - str++; + /* Skip one field, including preceding blanks. */ + for (field_started = 0; *str != '\0'; str += len) { + if ((len = mbtowc(&wc, str, MB_CUR_MAX)) == -1) { + (void)mbtowc(NULL, NULL, MB_CUR_MAX); + wc = L'?'; + len = 1; + } + if (iswblank(wc)) { + if (field_started) + break; + } else + field_started = 1; + } } - for (nchars = numchars; nchars-- && *str && *str != '\n'; ++str) - ; + + /* Skip some additional characters. */ + for (nchars = numchars; nchars-- && *str != '\0'; str += len) + if ((len = mblen(str, MB_CUR_MAX)) == -1) + len = 1; + return (str); }