nullstrcmp.c 449 B

12345678910111213141516171819202122
  1. /*
  2. * Compare two strings, just like strcmp, except that we tolerate null
  3. * pointers as a legal input, and define them to compare before any
  4. * non-null string (even the empty string).
  5. */
  6. #include <string.h>
  7. #include "defs.h"
  8. #include "misc.h"
  9. int nullstrcmp(const char *a, const char *b)
  10. {
  11. if (a == NULL && b == NULL)
  12. return 0;
  13. if (a == NULL)
  14. return -1;
  15. if (b == NULL)
  16. return +1;
  17. return strcmp(a, b);
  18. }