tests: fix scandirat wrapping 88/223188/3
authorMichal Bloch <m.bloch@samsung.com>
Fri, 24 Jan 2020 11:20:31 +0000 (12:20 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 24 Jan 2020 11:49:26 +0000 (12:49 +0100)
Change-Id: I381d623749ddc90deb2ddad7d828dbbc20c160df
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/tests/config.c

index 70e97a8..6d9fd3f 100644 (file)
@@ -22,30 +22,19 @@ static void conf_hash(const char *key, const char *value, void *userdata)
                *hash += *(value++);
 }
 
-static bool fail_scandirat;
-int __real_scandirat(int dirfd, const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **));
-int __wrap_scandirat(int dirfd, const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **))
-{
-       if (fail_scandirat)
-               return -1;
-
-       errno = 0;
-       int r = __real_scandirat(dirfd, dirp, namelist, filter, compar);
-
-       /* Workaround a build chain issue.
-        * There seems to be a mismatch between how the emulator emulates this syscall
-        * and how glibc expects it would. Fortunately, the symptoms are fairly unique
-        * with the EOVERFLOW error not really being possible otherwise (the directory
-        * we run this on has just two one-liner files). */
-       if (errno == EOVERFLOW)
-               exit(EXIT_SKIP); // that's game null and void
-
-       return r;
-}
-int __wrap_scandirat64(int dirfd, const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **))
-{
-       return __wrap_scandirat(dirfd, dirp, namelist, filter, compar);
+/* scandirat() is not the underlying syscall, it's just a libc wrapper for getdents.
+ * There's significant differences between getdents and getdents64 (unlike, for
+ * example open64, which just passes some flag we don't really care about) so we
+ * wouldn't be able to just redirect one to the other. Therefore the simplest
+ * way not to duplicate code is to just wrap both scandirat variantes the same way. */
+#define WRAP_SCANDIRAT(callname) \
+int __real_##callname(int dirfd, const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); \
+int __wrap_##callname(int dirfd, const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { \
+       return fail_scandirat ?  -1 : __real_##callname(dirfd, dirp, namelist, filter, compar); \
 }
+static bool fail_scandirat;
+WRAP_SCANDIRAT(scandirat)
+WRAP_SCANDIRAT(scandirat64)
 
 static bool fail_openat;
 int __real_openat(int dirfd, const char *pathname, int flags, mode_t mode);