use qsort_arg, which is a portable replacement for qsort_r

Apparently qsort_r signature on BSD systems (e.g. OS X) is not the
same as on Linux, causing strange SIGBUS errors.

Fixed based on report by Goulwen Reboux (Issue #1).