2

The patch of the final line fails on FreeBSD 10.2, but works on GNU:

#!/bin/sh
echo a > f1
printf '\0' >> f1
echo c >> f1
cp f1 f2
echo d >> f2
diff -au f1 f2 > diff
patch < diff

Is FreeBSD incapable of this? The man page does not mention null bytes.

1
  • 1
    It is not an uncommon limitation, since null-bytes are not used in text files. There is of course a FreeBSD port for GNU patch. Nov 17 '15 at 0:31
3

patch is designed for text files. Take a look at xxd, which can patch binary files. It should be available for FreeBSD as well.

2
  • how do I generate something similar to unified diff's for xxd? I want to handle multiple files... Nov 17 '15 at 12:06
  • That sounds like a new question. ;) Nov 17 '15 at 16:03
2

It is not an uncommon limitation, since null-bytes are not used in text files. There is of course a FreeBSD port for GNU patch.

For context, just looking at the manual pages for FreeBSD:

Both GNU patch and FreeBSD patch originated with Larry Wall's patch program, but the former has had more extensive changes. In particular, GNU patch was extended to handle the embedded nulls which might be output by GNU diff. Still, even that was done quite a while ago (around 1992 according to the changelog).

For whatever reason, the FreeBSD developers did not incorporate this change. If you need the feature on FreeBSD, you can use the port (or precompiled package) of GNU patch. See FreshPorts for a summary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.