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 10 static inline bool streq(const char *s1, const char *s2) 11 { 12 return strcmp(s1, s2) == 0; 13 } 14 15 static unsigned long long xstrtoull(const char *p, char **end) 16 { 17 if (*p == '0') { 18 *end = (char *)p + 1; 19 return 0; 20 } else if ('1' <= *p && *p <= '9') { 21 unsigned long long val; 22 23 errno = 0; 24 val = strtoull(p, end, 10); 25 assert(errno == 0); 26 return val; 27 } else 28 assert(0); 29 } 30 31 static struct dirent *xreaddir(DIR *d) 32 { 33 struct dirent *de; 34 35 errno = 0; 36 de = readdir(d); 37 assert(de || errno == 0); 38 return de; 39 } 40