From 1e99a982bf61474116b384a877df3f23d2fe5249 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Sun, 8 Jul 2012 15:48:57 +0000 Subject: Switch diff(1) binary file detection from !(isprint() || isspace()) to checking for embedded NULs, as was done for grep(1) some time ago. Avoids problems with e.g. latin1-encoded files being treated as binary, since isprint() uses only ASCII by default and diff(1) doesn't call setlocale(). prodded by and ok bluhm --- usr.bin/diff/diffreg.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 80907aa5554..14f0d17bf32 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.81 2012/05/22 12:30:24 millert Exp $ */ +/* $OpenBSD: diffreg.c,v 1.82 2012/07/08 15:48:56 stsp Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -1288,17 +1288,14 @@ static int asciifile(FILE *f) { unsigned char buf[BUFSIZ]; - size_t i, cnt; + size_t cnt; if (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])) - return (0); - return (1); + return (memchr(buf, '\0', cnt) == NULL); } #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0) -- cgit v1.2.3