Back to home page

OSCL-LXR

 
 

    


0001 #pragma once
0002 #undef NDEBUG
0003 #include <assert.h>
0004 #include <dirent.h>
0005 #include <errno.h>
0006 #include <stdbool.h>
0007 #include <stdlib.h>
0008 #include <string.h>
0009 #include <unistd.h>
0010 #include <sys/syscall.h>
0011 
0012 static inline pid_t sys_getpid(void)
0013 {
0014     return syscall(SYS_getpid);
0015 }
0016 
0017 static inline pid_t sys_gettid(void)
0018 {
0019     return syscall(SYS_gettid);
0020 }
0021 
0022 static inline bool streq(const char *s1, const char *s2)
0023 {
0024     return strcmp(s1, s2) == 0;
0025 }
0026 
0027 static unsigned long long xstrtoull(const char *p, char **end)
0028 {
0029     if (*p == '0') {
0030         *end = (char *)p + 1;
0031         return 0;
0032     } else if ('1' <= *p && *p <= '9') {
0033         unsigned long long val;
0034 
0035         errno = 0;
0036         val = strtoull(p, end, 10);
0037         assert(errno == 0);
0038         return val;
0039     } else
0040         assert(0);
0041 }
0042 
0043 static struct dirent *xreaddir(DIR *d)
0044 {
0045     struct dirent *de;
0046 
0047     errno = 0;
0048     de = readdir(d);
0049     assert(de || errno == 0);
0050     return de;
0051 }