Freebsd fixes

Hi, qsort_r on BSD differs in order of arguments (as well as order args of the compar function). This was causing tvheaded to crash on freebsd.

I have added a small wrapper "tvh_qsort_r" to fix this issue.