Add support for FreeBSD

Add supports for FreeBSD, all tests pass with the attached patch.