title: MacOS Big Sur: unexpected diff behaviour
body: <p>On MacOS Big Sur (Intel), I see the following unexpected behaviour, that I have not seen on Catalina. Prerequisites.</p>
  <ol>
  <li>My home directory /Users/foo resides on an afps-filesystem.</li>
  <li>/mnt/win10 is an SMB share mounted from a Win 10-machine (20H2).</li>
  </ol>
  <p>When I have a file where the filename contains unicode characters that can have more than one representation (<a href="https://stackoverflow.com/questions/38484369/why-does-the-c-runtime-on-mac-os-allow-both-precomposed-and-decomposed-utf-8">precomposed vs decomposed</a>) , the representation will change when copying the file from one filesystem to the other.</p>
  <pre><code>touch /Users/foo/ä
  cp /home/user/ä /mnt/win10/.
  </code></pre>
  <p>Then <code>diff /Users/foo/ä /mnt/win10/ä</code> shows no differences but <code>diff /Users/foo/. /mnt/win10/.</code> will rather unexpectedly result in:</p>
  <pre><code>Only in /Users/foo/.: ä
  Only in /mnt/win10/.: ä
  </code></pre>
  <p>Checking the encoding using a bit of Perl in the following script (call with `./script.pl /Users/foo/. /mnt/win10/.'):</p>
  <pre><code>use strict;
  use warnings;
  use utf8;
  use String::Dump qw( dump_hex dump_bin );
  
  while (my $d = shift) {
      opendir(D, &quot;$d&quot;) || die &quot;Can't open directory $d: $!\n&quot;;
      my @list = readdir(D);
      closedir(D);
  
      foreach my $f (@list) {
           print &quot;\$f = $f\n&quot;;
           print dump_hex($f);
           print &quot;\n&quot;;
       }
  }
  </code></pre>
  <p>will give the rather unexpected result for the afps-filesystem /Users/foo</p>
  <pre><code>$f = ä
  C3 A4
  </code></pre>
  <p>and for the SMB share /mnt/win10</p>
  <pre><code>$f = ä
  61 CC 88
  </code></pre>
  <p>So on the afps, we see the precomposed UTF-8 representation of 'ä', while on the SMB share, we find the decomposed UTF-8 representation (a small 'a' to be combined with two dots).<br />
  I have never encountered this with Catalina (but have not checked this for a while), I cannot find any documentation of a changed behaviour.<br />
  Needless to say that this obviously breaks things (Apple provided diff 2.8.1, homebrew provided diff 3.7). rsync 3.2.3 can work around this when you call it with <code>--iconv=utf-8-mac,utf-8-mac</code> (sic!).
  I have my own personal opinion if an OS should behave like that.<br />
  What is the proper approach to handle this in a POSIX compliant manner?
  Should I convert every filename with iconv(3) to utf-8-mac?</p>