[Top][All Lists]

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

Re: sed on binary files

From: Eric Blake
Subject: Re: sed on binary files
Date: Thu, 02 Oct 2008 06:46:38 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080914 Thunderbird/ Mnenhy/

Hash: SHA1

According to Ralf Wildenhues on 10/1/2008 11:32 PM:

Hi Ralf, Gary,

>> Is there any portable way to process files that contain NUL bytes?
> tr?  If you only need to compare for equality, then use cmp.

Equality is insufficient the way the test is currently written; I'm
checking that m4's errprint can directly output NUL, while warning
messages quote filenames, so I must normalize VPATH output such as:
  src/m4:../examples/null.m4:98: Warning: indir: undefined macro `\0-\0'
to match the expected error
  m4:examples/null.m4:98: Warning: indir: undefined macro `\0-\0'

I suppose I could split the test into two - with m4, any output line that
needs normalization should not be using raw NUL (error messages), while
anything that allows outputs raw NUL to stderr shouldn't need
normalization (errprint, dumpdef, trace output).  But that is not
necessarily trivial to do either (it means the m4 testsuite would have to
conditionally run sed, instead of its current attitude of always running
the sed normalization).

>> The Solaris man
>> pages mention that /usr/xpg4/bin/tr can handle NUL bytes, but not
>> /usr/bin/tr; maybe I could search for an adequate tr, and change all NUL
>> to some other byte that does not otherwise appear in my expected output
>> (with the added benefit that diff might not give up early with the
>> complaint that the files are binary), but I don't know if that is portable
>> either.
> That's what I'd try first, too.

I verified that Solaris /usr/xpg4/bin/tr can do the trick, but not

>> Any suggestions?  Is this worth documenting in the autoconf manual?
> I guess the bit that Solaris /usr/bin/tr is deficient, is (what about
> other vendors' tr?).  I wouldn't recommend a way to treat binary files
> in the manual, until there is actual experience with it, and then only
> if that deviates substantially from what Posix says.

I'll add a blurb to the autoconf manual on sed mentioning that it cannot
be used on binary files (although Posix already says that), as well as on
tr mentioning the Solaris /usr/bin/tr bug.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


reply via email to

[Prev in Thread] Current Thread [Next in Thread]