From 0a91b02cf37084adc092135a83dd43eeef056a4c Mon Sep 17 00:00:00 2001 From: stsp Date: Thu, 16 May 2013 12:44:48 +0000 Subject: Switch rcsdiff(1) binary file detection from !(isprint() || isspace()) to checking for embedded NULs, as was done for grep(1) and diff(1) some time ago. Avoids problems with e.g. latin1-encoded files being treated as binary, since isprint() uses only ASCII by default and rcsdiff(1) doesn't call setlocale(). ok sthen --- usr.bin/rcs/diff.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'usr.bin/rcs/diff.c') diff --git a/usr.bin/rcs/diff.c b/usr.bin/rcs/diff.c index 3dede6b45f2..260b2352882 100644 --- a/usr.bin/rcs/diff.c +++ b/usr.bin/rcs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.33 2011/04/20 19:34:16 nicm Exp $ */ +/* $OpenBSD: diff.c,v 1.34 2013/05/16 12:44:48 stsp Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -1132,17 +1132,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-59-g8ed1b