From owner-p4-projects@FreeBSD.ORG Wed Jul 2 14:30:08 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D9F281065686; Wed, 2 Jul 2008 14:30:07 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B4C71065680 for ; Wed, 2 Jul 2008 14:30:07 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8A3F28FC32 for ; Wed, 2 Jul 2008 14:30:07 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m62EU7ob044266 for ; Wed, 2 Jul 2008 14:30:07 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m62EU7xG044262 for perforce@freebsd.org; Wed, 2 Jul 2008 14:30:07 GMT (envelope-from gabor@freebsd.org) Date: Wed, 2 Jul 2008 14:30:07 GMT Message-Id: <200807021430.m62EU7xG044262@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 144485 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jul 2008 14:30:08 -0000 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 #include #include +#include +#include #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); }