add wrapper qsort to fix differences between BSD and GNU qsort_r

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.