pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk Don't rely on file(1) to distinguish text files fro...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/35199bcc59ce
branches:  trunk
changeset: 537861:35199bcc59ce
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Jan 18 11:16:08 2008 +0000

description:
Don't rely on file(1) to distinguish text files from binary files. This
has proven too unreliable in the past. For example, some Makefile.in
files were classified as "Quake I or II world or extension", just
because they happen to start with the letters "PACK". This method was
also subject to subtle differences in the locale.

The new method counts the number of NUL bytes in the file. It does not
depend on the locale settings. The -c option of wc(1) counts bytes, not
characters, and tr(1), which may interpret multibyte sequences, is
protected by LC_ALL. It should also work with the historical
implementations of tr(1) that could not handle NUL bytes and discarded
them, since this is exactly the intention.

See also:
* http://mail-index.netbsd.org/tech-pkg/2006/07/05/0000.html
* PR 37793

diffstat:

 mk/subst.mk |  10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diffs (24 lines):

diff -r 6f8000b8911c -r 35199bcc59ce mk/subst.mk
--- a/mk/subst.mk       Fri Jan 18 10:41:05 2008 +0000
+++ b/mk/subst.mk       Fri Jan 18 11:16:08 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.49 2008/01/18 10:41:05 rillig Exp $
+# $NetBSD: subst.mk,v 1.50 2008/01/18 11:16:08 rillig Exp $
 #
 # This Makefile fragment implements a general text replacement facility.
 # Package makefiles define a ``class'', for each of which a particular
@@ -63,10 +63,10 @@
 
 # _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file.
 _SUBST_IS_TEXT_FILE?= \
-       { ${TEST} -f "$$file"                                           \
-         && ${FILE_CMD} "$$file"                                       \
-            | ${EGREP} "(executable .* script|shell script|text|Assembler source|libtool|Quake I or II world or extension|XML)";       \
-       } >/dev/null 2>&1
+       { nchars=`${WC} -c < "$$file"`;                                 \
+         notnull=`LC_ALL=C ${TR} -d '\\0' < "$$file" | ${WC} -c`;      \
+         [ "$$nchars" = "$$notnull" ] || ${FALSE} ;                    \
+       }
 
 _SUBST_BACKUP_SUFFIX=  .subst.sav
 



Home | Main Index | Thread Index | Old Index