FIX Maildir code on BSD (Sergey Matveev)..
commit0c30b146f17086d6c71d4c307bcd0660aea5f1ac
authorSteffen (Daode) Nurpmeso <steffen@sdaoden.eu>
Sat, 16 Jan 2016 15:31:13 +0000 (16 16:31 +0100)
committerSteffen (Daode) Nurpmeso <steffen@sdaoden.eu>
Sat, 16 Jan 2016 15:31:13 +0000 (16 16:31 +0100)
treed1c21744bfc734cd24c6028dd1cd502b052bddd4
parent52b04d5ca2318071b646538ebb6df4c743ff9e8a
FIX Maildir code on BSD (Sergey Matveev)..

Sergey Matveev (stargrave at stargrave dot org) reported that
Maildir on (Free)BSD systems doesn't work because

 |Running s-nail under truss gives the following output (part of it, where
 |Maildir is checked):

 |    lseek(3,0x0,SEEK_END)                            = 142 (0x8e)

and it turns out it is an issue of undefined standard behaviour
regarding file offsets and files that have been opened append-only
with O_APPEND.  It was briefly handled by POSIX in May 2009 ([1-3]),
the most remarkable sentences being from Eric Blake

  The standard is silent, both behaviors are permitted.  In fact,
  this is the very bug that bit me when I released GNU M4 1.4.10,
  which worked on Linux but failed under BSD.

and Don Cragun

  [.] the above output is one correct result.  The other correct
  result would be for all three reported values to be 0.

  http://permalink.gmane.org/gmane.comp.standards.posix.austin.general/
  plus [1] 433, [2] 434, [3] 435

It is unlikely that the behaviour will change, but i for one do
consider the output of the following terrible.

  cd /tmp
  cat > test.c <<-EOT
  #include <stdio.h>
  #include <unistd.h>
  int
  main(int argc, char **argv){
          int c;
          FILE *fp;

          fp = fopen("/tmp/bsd-seek-ouch.txt", "a+");
          fputs("Hello, BSD!\n", fp);
          fseek(fp, 0, SEEK_SET);
          if(argc != 1)
                  printf("OFFSET %ld\n", ftell(fp));
          while((c = fgetc(fp)) != EOF)
                  putchar(c);
          fclose(fp);
          unlink("/tmp/bsd-seek-ouch.txt");
          return 0;
  }
  EOT
  cc -o test test.c
  echo one; ./test; echo two; ./test sigh

Add a minimal-invasive fix that should cover the problem.
However, Zopen() is a disaster and it should all be done
completely different than from what we have.
maildir.c
nailfuns.h
popen.c