Fix FreeBSD compiler errors.

Hi @perexg !
This commit is needed so that master branch can compile again on FreeBSD. (before broken).

No breakage of anything else. All changes for FreeBSD are wrapped in `#if defined(PLATFORM_FREEBSD)` statements.

Please merge so FreeBSD can stay current. This help a lot for the official FreeBSD port. Which otherwise is very old version (3.4) by Decke from long ago.

I've done basic test on FreeBSD and it compile OK. It seems can run OK in interactive mode (without doing fork). I haven't exhaustively tested all features on FreeBSD yet. This pull request is for just enable compilation.

Many thanks.