proc.h 659 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #undef NDEBUG
  3. #include <assert.h>
  4. #include <dirent.h>
  5. #include <errno.h>
  6. #include <stdbool.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. static inline bool streq(const char *s1, const char *s2)
  10. {
  11. return strcmp(s1, s2) == 0;
  12. }
  13. static unsigned long long xstrtoull(const char *p, char **end)
  14. {
  15. if (*p == '0') {
  16. *end = (char *)p + 1;
  17. return 0;
  18. } else if ('1' <= *p && *p <= '9') {
  19. unsigned long long val;
  20. errno = 0;
  21. val = strtoull(p, end, 10);
  22. assert(errno == 0);
  23. return val;
  24. } else
  25. assert(0);
  26. }
  27. static struct dirent *xreaddir(DIR *d)
  28. {
  29. struct dirent *de;
  30. errno = 0;
  31. de = readdir(d);
  32. assert(de || errno == 0);
  33. return de;
  34. }