util.c 377 B

123456789101112131415
  1. #include <stdlib.h>
  2. #include "util.h"
  3. // For consumption by qsort_r from stdlib
  4. // Return -1, 0, 1 depending on whether a < b, a == b, a > b
  5. // Ref:
  6. // - man 3 qsort_r
  7. // - https://stackoverflow.com/a/1788048
  8. int integer_difference_sign(const void *a, const void *b, void *data) {
  9. long n1 = *((long*)a);
  10. long n2 = *((long*)b);
  11. return (n1 > n2) - (n1 < n2);
  12. }