summaryrefslogtreecommitdiff
blob: 36a8ca649286db3acd5ae8cb7aad376f8bf719df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Index: trunk/test/src/test-scandir.c
===================================================================
--- trunk/test/src/test-scandir.c	(revision 0)
+++ trunk/test/src/test-scandir.c	(revision 343)
@@ -0,0 +1,35 @@
+#define _SVID_SOURCE
+#include <dirent.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main (int argc, char *argv[]) {
+    struct dirent **namelist;
+    int i, n;
+
+    if (argc != 3) {
+        fprintf(stderr, "Usage: %s chdir scandir\n", argv[0]);
+        exit(2);
+    }
+
+    if (*argv[1] && chdir(argv[1]) == -1) {
+        perror("chdir");
+        exit(1);
+    }
+
+    n = scandir(argv[2], &namelist, 0, alphasort);
+    if (n < 0) {
+        perror("scandir");
+        exit(1);
+    }
+    else {
+        for (i=0; i<n; i++) {
+            printf("%s\n", namelist[i]->d_name);
+            free(namelist[i]);
+        }
+        free(namelist);
+    }
+
+    return 0;
+}
+
Index: trunk/test/src/Makefile.am
===================================================================
--- trunk/test/src/Makefile.am	(revision 341)
+++ trunk/test/src/Makefile.am	(revision 343)
@@ -1 +1 @@
-check_PROGRAMS = test-chroot
+check_PROGRAMS = test-chroot test-scandir
Index: trunk/m4/scandir_argtypes.m4
===================================================================
--- trunk/m4/scandir_argtypes.m4	(revision 341)
+++ trunk/m4/scandir_argtypes.m4	(revision 343)
@@ -12,7 +12,7 @@
  for ac_arg1 in 'const char *dir'; do
   for ac_arg2 in 'struct dirent ***namelist'; do
    for ac_arg3 in 'int(*filter)(const struct dirent *)' 'int(*filter)(struct dirent *)'; do
-    for ac_arg4 in 'int(*compar)(const void *,const void *)'; do
+    for ac_arg4 in 'int(*compar)(const void *,const void *)' 'int(*compar)(const struct dirent **, const struct dirent **)'; do
      AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM(
 [AC_INCLUDES_DEFAULT
Index: trunk/m4/scandir64_argtypes.m4
===================================================================
--- trunk/m4/scandir64_argtypes.m4	(revision 0)
+++ trunk/m4/scandir64_argtypes.m4	(revision 343)
@@ -0,0 +1,48 @@
+dnl  AC_FUNC_SCANDIR64_ARGTYPES
+dnl  -------------------------
+dnl  Determine the correct type to be passed to each of the `scandir64'
+dnl  function's arguments, and define those types in `SCANDIR64_TYPE_ARG1',
+dnl  `SCANDIR64_TYPE_ARG2', `SCANDIR64_TYPE_ARG3' and `SCANDIR64_TYPE_ARG4'.
+AN_FUNCTION([scandir64], [AC_FUNC_SCANDIR64_ARGTYPES])
+AC_DEFUN([AC_FUNC_SCANDIR64_ARGTYPES],
+[AC_CHECK_HEADERS(dirent.h)
+AC_CACHE_CHECK([types of arguments for scandir64],
+[ac_cv_func_scandir64_args],
+[for ac_return in 'int'; do
+ for ac_arg1 in 'const char *dir'; do
+  for ac_arg2 in 'struct dirent64 ***namelist'; do
+   for ac_arg3 in 'int(*filter)(const struct dirent64 *)' 'int(*filter)(struct dirent64 *)'; do
+    for ac_arg4 in 'int(*compar)(const void *,const void *)' 'int(*compar)(const struct dirent64 **, const struct dirent64 **)'; do
+     AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+[AC_INCLUDES_DEFAULT
+#ifdef HAVE_UNISTD_H
+#include <dirent.h>
+#endif
+],
+  	    [extern $ac_return scandir64 ($ac_arg1, $ac_arg2, $ac_arg3, $ac_arg4);])],
+	    [ac_cv_func_scandir64_args="$ac_return;$ac_arg1;$ac_arg2;$ac_arg3;$ac_arg4"; break 5])
+    done
+   done
+  done
+ done
+done
+# Provide a safe default value.
+: ${ac_cv_func_scandir64_args='(default) int;const char *dir;struct dirent64 ***namelist;int(*filter)(const struct dirent64 *);int(*compar)(const void *,const void *)'}
+])
+ac_save_IFS=$IFS; IFS=';'
+set dummy `echo "$ac_cv_func_scandir64_args" | sed 's/^(default) //' | sed 's/\*/\*/g'`
+IFS=$ac_save_IFS
+shift
+AC_DEFINE_UNQUOTED(SCANDIR64_TYPE_RETURN, $[1],
+		   [Define to the type of return value for `scandir64'.])
+AC_DEFINE_UNQUOTED(SCANDIR64_TYPE_ARG1, $[2],
+		   [Define to the type of arg 1 for `scandir64'.])
+AC_DEFINE_UNQUOTED(SCANDIR64_TYPE_ARG2, $[3],
+		   [Define to the type of arg 2 for `scandir64'.])
+AC_DEFINE_UNQUOTED(SCANDIR64_TYPE_ARG3, $[4],
+		   [Define to the type of arg 3 for `scandir64'.])
+AC_DEFINE_UNQUOTED(SCANDIR64_TYPE_ARG4, $[5],
+		   [Define to the type of arg 4 for `scandir64'.])
+rm -f conftest*
+])
Index: trunk/configure.ac
===================================================================
--- trunk/configure.ac	(revision 341)
+++ trunk/configure.ac	(revision 343)
@@ -177,6 +177,7 @@
 
 AC_FUNC_READLINK_ARGTYPES
 AC_FUNC_SCANDIR_ARGTYPES
+AC_FUNC_SCANDIR64_ARGTYPES
 
 AC_CONFIG_FILES([ \
 Makefile \
Index: trunk/src/libfakechroot.c
===================================================================
--- trunk/src/libfakechroot.c	(revision 341)
+++ trunk/src/libfakechroot.c	(revision 343)
@@ -512,10 +512,10 @@
 #endif
 static int     (*next_rmdir) (const char *pathname) = NULL;
 #ifdef HAVE_SCANDIR
-static int     (*next_scandir) (const char *dir, struct dirent ***namelist, SCANDIR_TYPE_ARG3, int(*compar)(const void *, const void *)) = NULL;
+static int     (*next_scandir) (SCANDIR_TYPE_ARG1, SCANDIR_TYPE_ARG2, SCANDIR_TYPE_ARG3, SCANDIR_TYPE_ARG4) = NULL;
 #endif
 #ifdef HAVE_SCANDIR64
-static int     (*next_scandir64) (const char *dir, struct dirent64 ***namelist, int(*filter)(const struct dirent64 *), int(*compar)(const void *, const void *)) = NULL;
+static int     (*next_scandir64) (SCANDIR64_TYPE_ARG1, SCANDIR64_TYPE_ARG2, SCANDIR64_TYPE_ARG3, SCANDIR64_TYPE_ARG4) = NULL;
 #endif
 #ifdef HAVE_SETXATTR
 static int     (*next_setxattr) (const char *path, const char *name, const void *value, size_t size, int flags) = NULL;
@@ -2664,7 +2664,7 @@
 
 #ifdef HAVE_SCANDIR
 /* #include <dirent.h> */
-int scandir (const char *dir, struct dirent ***namelist, SCANDIR_TYPE_ARG3, int(*compar)(const void *, const void *))
+int scandir (SCANDIR_TYPE_ARG1, SCANDIR_TYPE_ARG2, SCANDIR_TYPE_ARG3, SCANDIR_TYPE_ARG4)
 {
     char *fakechroot_path, *fakechroot_ptr, fakechroot_buf[FAKECHROOT_MAXPATH];
     expand_chroot_path(dir, fakechroot_path, fakechroot_ptr, fakechroot_buf);
@@ -2676,7 +2676,7 @@
 
 #ifdef HAVE_SCANDIR64
 /* #include <dirent.h> */
-int scandir64 (const char *dir, struct dirent64 ***namelist, int(*filter)(const struct dirent64 *), int(*compar)(const void *, const void *))
+int scandir64 (SCANDIR64_TYPE_ARG1, SCANDIR64_TYPE_ARG2, SCANDIR64_TYPE_ARG3, SCANDIR64_TYPE_ARG4)
 {
     char *fakechroot_path, *fakechroot_ptr, fakechroot_buf[FAKECHROOT_MAXPATH];
     expand_chroot_path(dir, fakechroot_path, fakechroot_ptr, fakechroot_buf);