summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Sperling <stsp@cvs.openbsd.org>2012-07-08 15:48:57 +0000
committerStefan Sperling <stsp@cvs.openbsd.org>2012-07-08 15:48:57 +0000
commit1e99a982bf61474116b384a877df3f23d2fe5249 (patch)
tree93cabbf5ef269648ad5c27113bfc0fb7726c3351
parentc8b28223f84b129f5f72ef10b254b1e64b580f0c (diff)
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
-rw-r--r--usr.bin/diff/diffreg.c9
1 files 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)