Date: Wed, 2 Jul 2008 14:30:07 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 144485 for review Message-ID: <200807021430.m62EU7xG044262@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=144485 Change 144485 by gabor@gabor_server on 2008/07/02 14:29:53 - Fix handling of binary files - The fixed routine supports multibyte characters Affected files ... .. //depot/projects/soc2008/gabor_textproc/diff/diffreg.c#4 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/diff/diffreg.c#4 (text+ko) ==== @@ -86,6 +86,8 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <wchar.h> +#include <wctype.h> #include "diff.h" #include "pathnames.h" @@ -1280,17 +1282,22 @@ static int asciifile(FILE *f) { - char buf[BUFSIZ]; - int i, cnt; + wint_t ch = L'\0'; + size_t i; if (aflag || f == NULL) return (1); rewind(f); - cnt = fread(buf, 1, sizeof(buf), f); - for (i = 0; i < cnt; i++) - if (!isprint(buf[i]) && !isspace(buf[i])) + for (i = 0; i <= BUFSIZ; i++) { + if ((ch = fgetwc(f)) == WEOF) { + if (errno == EILSEQ) + return (0); + break; + } + if (!iswspace(ch) && iswcntrl(ch)) return (0); + } return (1); }help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807021430.m62EU7xG044262>
