add freebsd-specific platform encoding functions with support for ASCII, Latin-1, and UTF-8 locales

This is a slightly adjusted version of the linux-specific encoding functions.