Freebsd fixes

Added a qsort_r wrapper to account for differences between GNU and BSD qsort_r()s. Also changed a strdupa() to a variable length array.