Fix Darwin and FreeBSD OS type detection

Obtained in part from http://reviews.llvm.org/D6290