[lib] add support for BSDs

__TESTED UNDER FREEBSD 10__