Fix compilation on FreeBSD and OSX