More fixes

Several more fixes for platform compatibility.  With this it should ~~mostly work~~ on FreeBSD.  ~~For some reason execvP() doesn't want to work on FreeBSD and I'm really not sure why yet.~~  (Edit: With the latest commits it works perfectly on FreeBSD, I'd say it'll work on most any unix at this point, though more obscure ones might have tiny quirks that need fixing).

The open flags bit is probably a bit more important.  I noticed the lack of O_TRUNC quite a bit while testing.