(#693) Update file handling to work on Solaris

It appears that solaris has different file semantics from OSX and Linux.

  * flock() is allowed on the same file from the same process. On linux
    this ends up with a block of the second invocation of flock().
  * flock() is not allowed on a file that is opened for read-only.
  * fopen() with "a" causes a read to occur at the end of the file. On
    linux the read is at the beginning of the file.