PERFORCE change 144485 for review

Gabor Kovesdan gabor at FreeBSD.org
Wed Jul 2 14:30:08 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=144485

Change 144485 by gabor at 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);
 }
 


More information about the p4-projects mailing list