xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/nftw/test64.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker /* 10/31/2002   Port to LTP     [email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001   Port to Linux   [email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker  * NAME
25*49cdfc7eSAndroid Build Coastguard Worker  *      test64.c - Test functions for nftw64()
26*49cdfc7eSAndroid Build Coastguard Worker  */
27*49cdfc7eSAndroid Build Coastguard Worker 
28*49cdfc7eSAndroid Build Coastguard Worker #include "nftw64.h"
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker extern int callback(const char *path);
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker extern pathdata pathdat[];
33*49cdfc7eSAndroid Build Coastguard Worker extern struct list mnem[], badlist[];
34*49cdfc7eSAndroid Build Coastguard Worker extern char *dirlist[NDIRLISTENTS], *goodlist[];
35*49cdfc7eSAndroid Build Coastguard Worker extern int npathdats, ngoods, nbads, nmnem, visit, s2, next_fd[4];
36*49cdfc7eSAndroid Build Coastguard Worker extern FILE *temp;
37*49cdfc7eSAndroid Build Coastguard Worker /*
38*49cdfc7eSAndroid Build Coastguard Worker  *    void test1A()     - tests the assertion:
39*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
40*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall
41*49cdfc7eSAndroid Build Coastguard Worker  *      recursively descend the directory hierarchy rooted in path until it
42*49cdfc7eSAndroid Build Coastguard Worker  *      has traversed the whole tree, calling the function fn for each object
43*49cdfc7eSAndroid Build Coastguard Worker  *      in the directory tree, and return 0.
44*49cdfc7eSAndroid Build Coastguard Worker  */
45*49cdfc7eSAndroid Build Coastguard Worker 
test1A(void)46*49cdfc7eSAndroid Build Coastguard Worker void test1A(void)
47*49cdfc7eSAndroid Build Coastguard Worker {
48*49cdfc7eSAndroid Build Coastguard Worker 	int i, j, ret;
49*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
50*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
51*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64() succeeds\n");
52*49cdfc7eSAndroid Build Coastguard Worker #endif
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
55*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirh", test_func1, MAX_FD, 0)) == -1) {
56*49cdfc7eSAndroid Build Coastguard Worker 		perror("ERROR: nftw64 failed");
57*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
58*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
59*49cdfc7eSAndroid Build Coastguard Worker 	}
60*49cdfc7eSAndroid Build Coastguard Worker 
61*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
62*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
63*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
64*49cdfc7eSAndroid Build Coastguard Worker 	}
65*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
66*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: Whole tree traversed\n");
67*49cdfc7eSAndroid Build Coastguard Worker #endif
68*49cdfc7eSAndroid Build Coastguard Worker 
69*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != ngoods) {
70*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: Count of objects visited incorrect\n");
71*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "       Expected %d, Received %d\n", ngoods,
72*49cdfc7eSAndroid Build Coastguard Worker 			visit);
73*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
74*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
75*49cdfc7eSAndroid Build Coastguard Worker 	}
76*49cdfc7eSAndroid Build Coastguard Worker 
77*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < visit; i++) {
78*49cdfc7eSAndroid Build Coastguard Worker 		for (j = 0; j < ngoods; j++) {
79*49cdfc7eSAndroid Build Coastguard Worker 			if (strcmp(dirlist[i], goodlist[j]) == 0) {
80*49cdfc7eSAndroid Build Coastguard Worker 				free(dirlist[i]);
81*49cdfc7eSAndroid Build Coastguard Worker 				dirlist[i] = NULL;
82*49cdfc7eSAndroid Build Coastguard Worker 				break;
83*49cdfc7eSAndroid Build Coastguard Worker 			}
84*49cdfc7eSAndroid Build Coastguard Worker 		}
85*49cdfc7eSAndroid Build Coastguard Worker 	}
86*49cdfc7eSAndroid Build Coastguard Worker 
87*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < visit; i++) {
88*49cdfc7eSAndroid Build Coastguard Worker 		if (dirlist[i] != NULL) {
89*49cdfc7eSAndroid Build Coastguard Worker 			free(dirlist[i]);
90*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "ERROR: Unexpected visit to %s\n",
91*49cdfc7eSAndroid Build Coastguard Worker 				dirlist[i]);
92*49cdfc7eSAndroid Build Coastguard Worker 			cleanup_function();
93*49cdfc7eSAndroid Build Coastguard Worker 			fail_exit();
94*49cdfc7eSAndroid Build Coastguard Worker 		}
95*49cdfc7eSAndroid Build Coastguard Worker 	}
96*49cdfc7eSAndroid Build Coastguard Worker }
97*49cdfc7eSAndroid Build Coastguard Worker 
98*49cdfc7eSAndroid Build Coastguard Worker /*
99*49cdfc7eSAndroid Build Coastguard Worker  *    void test2A()     - tests the assertion:
100*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
101*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when flags
102*49cdfc7eSAndroid Build Coastguard Worker  *      contains FTW_PHYS shall not traverse symbolic links.
103*49cdfc7eSAndroid Build Coastguard Worker  */
104*49cdfc7eSAndroid Build Coastguard Worker 
test2A(void)105*49cdfc7eSAndroid Build Coastguard Worker void test2A(void)
106*49cdfc7eSAndroid Build Coastguard Worker {
107*49cdfc7eSAndroid Build Coastguard Worker 	int i, ret;
108*49cdfc7eSAndroid Build Coastguard Worker 
109*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
110*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
111*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
112*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 with FTW_PHYS does not follow symbolic links\n");
113*49cdfc7eSAndroid Build Coastguard Worker #endif
114*49cdfc7eSAndroid Build Coastguard Worker 
115*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
116*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirl", test_func1, MAX_FD, FTW_PHYS))
117*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
118*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
119*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
120*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
121*49cdfc7eSAndroid Build Coastguard Worker 	}
122*49cdfc7eSAndroid Build Coastguard Worker 
123*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
124*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
125*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
126*49cdfc7eSAndroid Build Coastguard Worker 	}
127*49cdfc7eSAndroid Build Coastguard Worker 
128*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != NO_LINK_CNT) {
129*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
130*49cdfc7eSAndroid Build Coastguard Worker 			"ERROR: Expected %d files to be visited.  nftw64() visited %d\n",
131*49cdfc7eSAndroid Build Coastguard Worker 			NO_LINK_CNT, visit);
132*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
133*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
134*49cdfc7eSAndroid Build Coastguard Worker 	}
135*49cdfc7eSAndroid Build Coastguard Worker 
136*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < visit; i++) {
137*49cdfc7eSAndroid Build Coastguard Worker 		if (dirlist[i] != NULL)
138*49cdfc7eSAndroid Build Coastguard Worker 			free(dirlist[i]);
139*49cdfc7eSAndroid Build Coastguard Worker 	}
140*49cdfc7eSAndroid Build Coastguard Worker }
141*49cdfc7eSAndroid Build Coastguard Worker 
142*49cdfc7eSAndroid Build Coastguard Worker /*
143*49cdfc7eSAndroid Build Coastguard Worker  *    void test3A()     - tests the assertion:
144*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
145*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when flags
146*49cdfc7eSAndroid Build Coastguard Worker  *      does not contain FTW_PHYS shall follow links instead of reporting
147*49cdfc7eSAndroid Build Coastguard Worker  *      them and shall not report the same file twice.
148*49cdfc7eSAndroid Build Coastguard Worker  */
149*49cdfc7eSAndroid Build Coastguard Worker 
test3A(void)150*49cdfc7eSAndroid Build Coastguard Worker void test3A(void)
151*49cdfc7eSAndroid Build Coastguard Worker {
152*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
153*49cdfc7eSAndroid Build Coastguard Worker 
154*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
155*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
156*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 without FTW_PHYS follows symbolic links\n");
157*49cdfc7eSAndroid Build Coastguard Worker #endif
158*49cdfc7eSAndroid Build Coastguard Worker 
159*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
160*49cdfc7eSAndroid Build Coastguard Worker 
161*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirl", test_func3, MAX_FD, 0)) == -1) {
162*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
163*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
164*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
165*49cdfc7eSAndroid Build Coastguard Worker 	}
166*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
167*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
168*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
169*49cdfc7eSAndroid Build Coastguard Worker 	}
170*49cdfc7eSAndroid Build Coastguard Worker 
171*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != LINK_CNT - 1) {
172*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
173*49cdfc7eSAndroid Build Coastguard Worker 			"ERROR: Expected %d files to be visited.  nftw64() visited %d\n",
174*49cdfc7eSAndroid Build Coastguard Worker 			LINK_CNT - 1, visit);
175*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
176*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
177*49cdfc7eSAndroid Build Coastguard Worker 	}
178*49cdfc7eSAndroid Build Coastguard Worker }
179*49cdfc7eSAndroid Build Coastguard Worker 
180*49cdfc7eSAndroid Build Coastguard Worker /*
181*49cdfc7eSAndroid Build Coastguard Worker  *    void test4A()     - tests the assertion:
182*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
183*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when flags
184*49cdfc7eSAndroid Build Coastguard Worker  *      contains FTW_DEPTH shall report all files in a directory before
185*49cdfc7eSAndroid Build Coastguard Worker  *      reporting the directory.
186*49cdfc7eSAndroid Build Coastguard Worker  */
187*49cdfc7eSAndroid Build Coastguard Worker 
test4A(void)188*49cdfc7eSAndroid Build Coastguard Worker void test4A(void)
189*49cdfc7eSAndroid Build Coastguard Worker {
190*49cdfc7eSAndroid Build Coastguard Worker 	char path[] = "./tmp/data/d777";
191*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
192*49cdfc7eSAndroid Build Coastguard Worker 
193*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
194*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
195*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: Verify traversal with FTW_DEPTH set\n");
196*49cdfc7eSAndroid Build Coastguard Worker #endif
197*49cdfc7eSAndroid Build Coastguard Worker 
198*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
199*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret_val = nftw64(path, test_func4, MAX_FD, FTW_DEPTH)) == -1) {
200*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
201*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
202*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
203*49cdfc7eSAndroid Build Coastguard Worker 	}
204*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val != 999) {
205*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: %s never visited\n", path);
206*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
207*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
208*49cdfc7eSAndroid Build Coastguard Worker 	}
209*49cdfc7eSAndroid Build Coastguard Worker 
210*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != 2) {
211*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: Visited directory before contents\n");
212*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
213*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
214*49cdfc7eSAndroid Build Coastguard Worker 	}
215*49cdfc7eSAndroid Build Coastguard Worker }
216*49cdfc7eSAndroid Build Coastguard Worker 
217*49cdfc7eSAndroid Build Coastguard Worker /*
218*49cdfc7eSAndroid Build Coastguard Worker  *    void test5A()     - tests the assertion:
219*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
220*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when flags
221*49cdfc7eSAndroid Build Coastguard Worker  *      does not contain FTW_DEPTH shall report a directory before reporting
222*49cdfc7eSAndroid Build Coastguard Worker  *      the files in that directory.
223*49cdfc7eSAndroid Build Coastguard Worker  */
224*49cdfc7eSAndroid Build Coastguard Worker 
test5A(void)225*49cdfc7eSAndroid Build Coastguard Worker void test5A(void)
226*49cdfc7eSAndroid Build Coastguard Worker {
227*49cdfc7eSAndroid Build Coastguard Worker 	char path[] = "./tmp/data/d777";
228*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
229*49cdfc7eSAndroid Build Coastguard Worker 
230*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
231*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
232*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: Verify traversal without FTW_DEPTH set\n");
233*49cdfc7eSAndroid Build Coastguard Worker #endif
234*49cdfc7eSAndroid Build Coastguard Worker 
235*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
236*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret_val = nftw64(path, test_func4, MAX_FD, 0)) == -1) {
237*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
238*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
239*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
240*49cdfc7eSAndroid Build Coastguard Worker 	}
241*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val != 999) {
242*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: %s never visited\n", path);
243*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
244*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
245*49cdfc7eSAndroid Build Coastguard Worker 	}
246*49cdfc7eSAndroid Build Coastguard Worker 
247*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != 1) {
248*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: Visited contents before directory\n");
249*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
250*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
251*49cdfc7eSAndroid Build Coastguard Worker 	}
252*49cdfc7eSAndroid Build Coastguard Worker }
253*49cdfc7eSAndroid Build Coastguard Worker 
254*49cdfc7eSAndroid Build Coastguard Worker /*
255*49cdfc7eSAndroid Build Coastguard Worker  *    void test6A()     - tests the assertion:
256*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
257*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when flags
258*49cdfc7eSAndroid Build Coastguard Worker  *      contains FTW_CHDIR shall change the current working directory to each
259*49cdfc7eSAndroid Build Coastguard Worker  *      directory as it reports files in that directory.
260*49cdfc7eSAndroid Build Coastguard Worker  */
261*49cdfc7eSAndroid Build Coastguard Worker 
test6A(void)262*49cdfc7eSAndroid Build Coastguard Worker void test6A(void)
263*49cdfc7eSAndroid Build Coastguard Worker {
264*49cdfc7eSAndroid Build Coastguard Worker 	char path[PATH_MAX + NAME_MAX];
265*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
266*49cdfc7eSAndroid Build Coastguard Worker 
267*49cdfc7eSAndroid Build Coastguard Worker 	if (getcwd(path, sizeof(path)) == NULL) {
268*49cdfc7eSAndroid Build Coastguard Worker 		perror("getcwd");
269*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
270*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
271*49cdfc7eSAndroid Build Coastguard Worker 	}
272*49cdfc7eSAndroid Build Coastguard Worker 	(void)strcat(path, "/tmp/data/dirh");
273*49cdfc7eSAndroid Build Coastguard Worker 
274*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
275*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
276*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
277*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 with FTW_CHDIR changes to each dir before reporting files in it\n");
278*49cdfc7eSAndroid Build Coastguard Worker #endif
279*49cdfc7eSAndroid Build Coastguard Worker 
280*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = nftw64(path, test_func5, MAX_FD, FTW_CHDIR);
281*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1) {
282*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
283*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
284*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
285*49cdfc7eSAndroid Build Coastguard Worker 	}
286*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret_val == 998) || (ret_val == 999)) {
287*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
288*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
289*49cdfc7eSAndroid Build Coastguard Worker 	}
290*49cdfc7eSAndroid Build Coastguard Worker }
291*49cdfc7eSAndroid Build Coastguard Worker 
292*49cdfc7eSAndroid Build Coastguard Worker /*
293*49cdfc7eSAndroid Build Coastguard Worker  *    void test7A()     - tests the assertion:
294*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
295*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
296*49cdfc7eSAndroid Build Coastguard Worker  *      the path-name of the current object as the first argument of the
297*49cdfc7eSAndroid Build Coastguard Worker  *      function fn.
298*49cdfc7eSAndroid Build Coastguard Worker  */
299*49cdfc7eSAndroid Build Coastguard Worker 
test7A(void)300*49cdfc7eSAndroid Build Coastguard Worker void test7A(void)
301*49cdfc7eSAndroid Build Coastguard Worker {
302*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
303*49cdfc7eSAndroid Build Coastguard Worker 
304*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
305*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
306*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
307*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes pathname as first argument to fn()\n");
308*49cdfc7eSAndroid Build Coastguard Worker #endif
309*49cdfc7eSAndroid Build Coastguard Worker 
310*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func7, MAX_FD, 0)) == -1) {
311*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
312*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
313*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
314*49cdfc7eSAndroid Build Coastguard Worker 	}
315*49cdfc7eSAndroid Build Coastguard Worker 
316*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
317*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
318*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
319*49cdfc7eSAndroid Build Coastguard Worker 	}
320*49cdfc7eSAndroid Build Coastguard Worker }
321*49cdfc7eSAndroid Build Coastguard Worker 
322*49cdfc7eSAndroid Build Coastguard Worker /*
323*49cdfc7eSAndroid Build Coastguard Worker  *    void test8A()    - tests the assertion:
324*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
325*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass a
326*49cdfc7eSAndroid Build Coastguard Worker  *      pointer to a stat structure containing information about the current
327*49cdfc7eSAndroid Build Coastguard Worker  *      object as the second argument to fn.
328*49cdfc7eSAndroid Build Coastguard Worker  */
329*49cdfc7eSAndroid Build Coastguard Worker 
test8A(void)330*49cdfc7eSAndroid Build Coastguard Worker void test8A(void)
331*49cdfc7eSAndroid Build Coastguard Worker {
332*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
333*49cdfc7eSAndroid Build Coastguard Worker 
334*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
335*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
336*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
337*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes stat struct as second argument to fn()\n");
338*49cdfc7eSAndroid Build Coastguard Worker #endif
339*49cdfc7eSAndroid Build Coastguard Worker 
340*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func8, MAX_FD, 0)) == -1) {
341*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
342*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
343*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
344*49cdfc7eSAndroid Build Coastguard Worker 	}
345*49cdfc7eSAndroid Build Coastguard Worker 
346*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
347*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
348*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
349*49cdfc7eSAndroid Build Coastguard Worker 	}
350*49cdfc7eSAndroid Build Coastguard Worker }
351*49cdfc7eSAndroid Build Coastguard Worker 
352*49cdfc7eSAndroid Build Coastguard Worker /*
353*49cdfc7eSAndroid Build Coastguard Worker  *    void test9A()    - tests the assertion:
354*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
355*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
356*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_F as the third argument of the function fn when the object is a
357*49cdfc7eSAndroid Build Coastguard Worker  *      file
358*49cdfc7eSAndroid Build Coastguard Worker  */
359*49cdfc7eSAndroid Build Coastguard Worker 
test9A(void)360*49cdfc7eSAndroid Build Coastguard Worker void test9A(void)
361*49cdfc7eSAndroid Build Coastguard Worker {
362*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
363*49cdfc7eSAndroid Build Coastguard Worker 
364*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
365*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
366*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
367*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes FTW_F as third arg to fn() for files\n");
368*49cdfc7eSAndroid Build Coastguard Worker #endif
369*49cdfc7eSAndroid Build Coastguard Worker 
370*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func9, MAX_FD, FTW_PHYS))
371*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
372*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
373*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
374*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
375*49cdfc7eSAndroid Build Coastguard Worker 	}
376*49cdfc7eSAndroid Build Coastguard Worker 
377*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
378*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
379*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
380*49cdfc7eSAndroid Build Coastguard Worker 	}
381*49cdfc7eSAndroid Build Coastguard Worker }
382*49cdfc7eSAndroid Build Coastguard Worker 
383*49cdfc7eSAndroid Build Coastguard Worker /*
384*49cdfc7eSAndroid Build Coastguard Worker  *    void test10A()    - tests the assertion:
385*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
386*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
387*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_D as the third argument of the function fn when the object is a
388*49cdfc7eSAndroid Build Coastguard Worker  *      directory.
389*49cdfc7eSAndroid Build Coastguard Worker  */
390*49cdfc7eSAndroid Build Coastguard Worker 
test10A(void)391*49cdfc7eSAndroid Build Coastguard Worker void test10A(void)
392*49cdfc7eSAndroid Build Coastguard Worker {
393*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
394*49cdfc7eSAndroid Build Coastguard Worker 
395*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
396*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
397*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
398*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes FTW_D as third arg to fn() when file is directory\n");
399*49cdfc7eSAndroid Build Coastguard Worker #endif
400*49cdfc7eSAndroid Build Coastguard Worker 
401*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func10, MAX_FD, FTW_PHYS))
402*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
403*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
404*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
405*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
406*49cdfc7eSAndroid Build Coastguard Worker 	}
407*49cdfc7eSAndroid Build Coastguard Worker 
408*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
409*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
410*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
411*49cdfc7eSAndroid Build Coastguard Worker 	}
412*49cdfc7eSAndroid Build Coastguard Worker }
413*49cdfc7eSAndroid Build Coastguard Worker 
414*49cdfc7eSAndroid Build Coastguard Worker /*
415*49cdfc7eSAndroid Build Coastguard Worker  *    void test11A()    - tests the assertion:
416*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
417*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
418*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_DP as the third argument of the function fn when the object is a
419*49cdfc7eSAndroid Build Coastguard Worker  *      directory and subdirectories have been visited.
420*49cdfc7eSAndroid Build Coastguard Worker  */
421*49cdfc7eSAndroid Build Coastguard Worker 
test11A(void)422*49cdfc7eSAndroid Build Coastguard Worker void test11A(void)
423*49cdfc7eSAndroid Build Coastguard Worker {
424*49cdfc7eSAndroid Build Coastguard Worker 	int i, ret;
425*49cdfc7eSAndroid Build Coastguard Worker 
426*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < nbads; i++)
427*49cdfc7eSAndroid Build Coastguard Worker 		if (badlist[i].i == FTW_D)
428*49cdfc7eSAndroid Build Coastguard Worker 			badlist[i].i = FTW_DP;
429*49cdfc7eSAndroid Build Coastguard Worker 
430*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
431*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
432*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
433*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes FTW_DP when file is directory and subdirs already visited\n");
434*49cdfc7eSAndroid Build Coastguard Worker #endif
435*49cdfc7eSAndroid Build Coastguard Worker 
436*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func11, MAX_FD, FTW_DEPTH |
437*49cdfc7eSAndroid Build Coastguard Worker 			  FTW_PHYS)) == -1) {
438*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
439*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
440*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
441*49cdfc7eSAndroid Build Coastguard Worker 	}
442*49cdfc7eSAndroid Build Coastguard Worker 
443*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
444*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
445*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
446*49cdfc7eSAndroid Build Coastguard Worker 	}
447*49cdfc7eSAndroid Build Coastguard Worker }
448*49cdfc7eSAndroid Build Coastguard Worker 
449*49cdfc7eSAndroid Build Coastguard Worker /*
450*49cdfc7eSAndroid Build Coastguard Worker  *    void test12A()    - tests the assertion:
451*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
452*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
453*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_SL as the third argument of the function fn when the object is a
454*49cdfc7eSAndroid Build Coastguard Worker  *      symbolic link.
455*49cdfc7eSAndroid Build Coastguard Worker  */
456*49cdfc7eSAndroid Build Coastguard Worker 
test12A(void)457*49cdfc7eSAndroid Build Coastguard Worker void test12A(void)
458*49cdfc7eSAndroid Build Coastguard Worker {
459*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
460*49cdfc7eSAndroid Build Coastguard Worker 
461*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
462*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
463*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
464*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 wth FTW_PHYS passes FTW_SL when file is symlink\n");
465*49cdfc7eSAndroid Build Coastguard Worker #endif
466*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func12, MAX_FD, FTW_PHYS))
467*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
468*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
469*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
470*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
471*49cdfc7eSAndroid Build Coastguard Worker 	}
472*49cdfc7eSAndroid Build Coastguard Worker 
473*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
474*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
475*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
476*49cdfc7eSAndroid Build Coastguard Worker 	}
477*49cdfc7eSAndroid Build Coastguard Worker }
478*49cdfc7eSAndroid Build Coastguard Worker 
479*49cdfc7eSAndroid Build Coastguard Worker /*
480*49cdfc7eSAndroid Build Coastguard Worker  *    void test13A()    - tests the assertion:
481*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
482*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
483*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_SLN as the third argument of the function fn when the object is a
484*49cdfc7eSAndroid Build Coastguard Worker  *      symbolic link that does not name an existing file.
485*49cdfc7eSAndroid Build Coastguard Worker  */
486*49cdfc7eSAndroid Build Coastguard Worker 
test13A(void)487*49cdfc7eSAndroid Build Coastguard Worker void test13A(void)
488*49cdfc7eSAndroid Build Coastguard Worker {
489*49cdfc7eSAndroid Build Coastguard Worker 	int i, ret;
490*49cdfc7eSAndroid Build Coastguard Worker 
491*49cdfc7eSAndroid Build Coastguard Worker 	if (unlink("./tmp/byebye") == -1) {
492*49cdfc7eSAndroid Build Coastguard Worker 		perror("unlink");
493*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
494*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
495*49cdfc7eSAndroid Build Coastguard Worker 	}
496*49cdfc7eSAndroid Build Coastguard Worker 
497*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < nbads; i++)
498*49cdfc7eSAndroid Build Coastguard Worker 		if (badlist[i].i == FTW_SL)
499*49cdfc7eSAndroid Build Coastguard Worker 			badlist[i].i = FTW_SLN;
500*49cdfc7eSAndroid Build Coastguard Worker 
501*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
502*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
503*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 with FTW_PHYS passes FTW_SLN when file");
504*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, " is symlink pointing \n to non-existent file\n");
505*49cdfc7eSAndroid Build Coastguard Worker #endif
506*49cdfc7eSAndroid Build Coastguard Worker 
507*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func13, MAX_FD, FTW_PHYS))
508*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
509*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
510*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
511*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
512*49cdfc7eSAndroid Build Coastguard Worker 	}
513*49cdfc7eSAndroid Build Coastguard Worker 
514*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
515*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
516*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
517*49cdfc7eSAndroid Build Coastguard Worker 	}
518*49cdfc7eSAndroid Build Coastguard Worker }
519*49cdfc7eSAndroid Build Coastguard Worker 
520*49cdfc7eSAndroid Build Coastguard Worker /*
521*49cdfc7eSAndroid Build Coastguard Worker  *    void test14A()    - tests the assertion:
522*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
523*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
524*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_DNR as the third argument of the function fn when the object is a
525*49cdfc7eSAndroid Build Coastguard Worker  *      directory that cannot be read.
526*49cdfc7eSAndroid Build Coastguard Worker  */
527*49cdfc7eSAndroid Build Coastguard Worker 
test14A(void)528*49cdfc7eSAndroid Build Coastguard Worker void test14A(void)
529*49cdfc7eSAndroid Build Coastguard Worker {
530*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
531*49cdfc7eSAndroid Build Coastguard Worker 
532*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
533*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
534*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
535*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 passes FTW_DNR when file is directory that cannot be read\n");
536*49cdfc7eSAndroid Build Coastguard Worker #endif
537*49cdfc7eSAndroid Build Coastguard Worker 
538*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/d333", test_func14, MAX_FD, 0)) == -1) {
539*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
540*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
541*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
542*49cdfc7eSAndroid Build Coastguard Worker 	}
543*49cdfc7eSAndroid Build Coastguard Worker 
544*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
545*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
546*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
547*49cdfc7eSAndroid Build Coastguard Worker 	}
548*49cdfc7eSAndroid Build Coastguard Worker }
549*49cdfc7eSAndroid Build Coastguard Worker 
550*49cdfc7eSAndroid Build Coastguard Worker /*
551*49cdfc7eSAndroid Build Coastguard Worker  *    void test15A()    - tests the assertion:
552*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
553*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
554*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_NS as the third argument of the function fn when stat() failed on
555*49cdfc7eSAndroid Build Coastguard Worker  *      the object because of lack of appropriate permission.
556*49cdfc7eSAndroid Build Coastguard Worker  */
557*49cdfc7eSAndroid Build Coastguard Worker 
test15A(void)558*49cdfc7eSAndroid Build Coastguard Worker void test15A(void)
559*49cdfc7eSAndroid Build Coastguard Worker {
560*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
561*49cdfc7eSAndroid Build Coastguard Worker 
562*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
563*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
564*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
565*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64(path, fn, depth, FTW_PHYS) passes FTW_NS when dir unsearchable\n");
566*49cdfc7eSAndroid Build Coastguard Worker #endif
567*49cdfc7eSAndroid Build Coastguard Worker 
568*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/d666", test_func15, MAX_FD, FTW_PHYS))
569*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
570*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
571*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
572*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
573*49cdfc7eSAndroid Build Coastguard Worker 	}
574*49cdfc7eSAndroid Build Coastguard Worker 
575*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
576*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
577*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
578*49cdfc7eSAndroid Build Coastguard Worker 	}
579*49cdfc7eSAndroid Build Coastguard Worker }
580*49cdfc7eSAndroid Build Coastguard Worker 
581*49cdfc7eSAndroid Build Coastguard Worker /*
582*49cdfc7eSAndroid Build Coastguard Worker  *    void test16A()    - tests the assertion:
583*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
584*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass a
585*49cdfc7eSAndroid Build Coastguard Worker  *      structure which contains the offset into the pathname of the object
586*49cdfc7eSAndroid Build Coastguard Worker  *      and the depth relative to the root of the walk starting from 0 as the
587*49cdfc7eSAndroid Build Coastguard Worker  *      fourth argument of the function fn.
588*49cdfc7eSAndroid Build Coastguard Worker  */
589*49cdfc7eSAndroid Build Coastguard Worker 
test16A(void)590*49cdfc7eSAndroid Build Coastguard Worker void test16A(void)
591*49cdfc7eSAndroid Build Coastguard Worker {
592*49cdfc7eSAndroid Build Coastguard Worker 	char path[PATH_MAX + NAME_MAX];
593*49cdfc7eSAndroid Build Coastguard Worker 	char orig[PATH_MAX + NAME_MAX];
594*49cdfc7eSAndroid Build Coastguard Worker 
595*49cdfc7eSAndroid Build Coastguard Worker 	if (getcwd(orig, sizeof(orig)) == NULL) {
596*49cdfc7eSAndroid Build Coastguard Worker 		perror("getcwd on original wd");
597*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
598*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
599*49cdfc7eSAndroid Build Coastguard Worker 	}
600*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(path, orig);
601*49cdfc7eSAndroid Build Coastguard Worker 	(void)strcat(path, "/tmp/data/dirg");
602*49cdfc7eSAndroid Build Coastguard Worker 
603*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
604*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
605*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 with absolute pathname %s\n", path);
606*49cdfc7eSAndroid Build Coastguard Worker #endif
607*49cdfc7eSAndroid Build Coastguard Worker 
608*49cdfc7eSAndroid Build Coastguard Worker 	if ((s2 = nftw64(path, test_func16, MAX_FD, 0)) == -1) {
609*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
610*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
611*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
612*49cdfc7eSAndroid Build Coastguard Worker 	}
613*49cdfc7eSAndroid Build Coastguard Worker 	if (s2 == 999) {
614*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
615*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
616*49cdfc7eSAndroid Build Coastguard Worker 	}
617*49cdfc7eSAndroid Build Coastguard Worker 
618*49cdfc7eSAndroid Build Coastguard Worker 	(void)strcpy(path, "./tmp/data/dirg");
619*49cdfc7eSAndroid Build Coastguard Worker 
620*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
621*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 with relative pathname %s\n", path);
622*49cdfc7eSAndroid Build Coastguard Worker #endif
623*49cdfc7eSAndroid Build Coastguard Worker 
624*49cdfc7eSAndroid Build Coastguard Worker 	if ((s2 = nftw64(path, test_func16, MAX_FD, 0)) == -1) {
625*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
626*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
627*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
628*49cdfc7eSAndroid Build Coastguard Worker 	}
629*49cdfc7eSAndroid Build Coastguard Worker 
630*49cdfc7eSAndroid Build Coastguard Worker 	if (s2 == 999) {
631*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
632*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
633*49cdfc7eSAndroid Build Coastguard Worker 	}
634*49cdfc7eSAndroid Build Coastguard Worker }
635*49cdfc7eSAndroid Build Coastguard Worker 
636*49cdfc7eSAndroid Build Coastguard Worker /*
637*49cdfc7eSAndroid Build Coastguard Worker  *    void test17A()    - tests the assertion:
638*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
639*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
640*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_SL as the third argument to the function fn if and only if the
641*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_PHYS flag is included in flags.
642*49cdfc7eSAndroid Build Coastguard Worker  */
643*49cdfc7eSAndroid Build Coastguard Worker 
test17A(void)644*49cdfc7eSAndroid Build Coastguard Worker void test17A(void)
645*49cdfc7eSAndroid Build Coastguard Worker {
646*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
647*49cdfc7eSAndroid Build Coastguard Worker 
648*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
649*49cdfc7eSAndroid Build Coastguard Worker 
650*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
651*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
652*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 with FTW_PHYS passes FTW_SL for symlink\n");
653*49cdfc7eSAndroid Build Coastguard Worker #endif
654*49cdfc7eSAndroid Build Coastguard Worker 
655*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirl", test_func17, MAX_FD, FTW_PHYS))
656*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
657*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
658*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
659*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
660*49cdfc7eSAndroid Build Coastguard Worker 	}
661*49cdfc7eSAndroid Build Coastguard Worker 	if (ret != 999) {
662*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: nftw64() failed to find symbolic link\n");
663*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
664*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
665*49cdfc7eSAndroid Build Coastguard Worker 	}
666*49cdfc7eSAndroid Build Coastguard Worker 
667*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
668*49cdfc7eSAndroid Build Coastguard Worker 
669*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
670*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
671*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: nftw64 without FTW_PHYS does not pass FTW_SL for symlink\n");
672*49cdfc7eSAndroid Build Coastguard Worker #endif
673*49cdfc7eSAndroid Build Coastguard Worker 
674*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirl", test_func17, MAX_FD, 0)) == -1) {
675*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
676*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
677*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
678*49cdfc7eSAndroid Build Coastguard Worker 	}
679*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
680*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: nftw64() found symbolic link\n");
681*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
682*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
683*49cdfc7eSAndroid Build Coastguard Worker 	}
684*49cdfc7eSAndroid Build Coastguard Worker }
685*49cdfc7eSAndroid Build Coastguard Worker 
686*49cdfc7eSAndroid Build Coastguard Worker /*
687*49cdfc7eSAndroid Build Coastguard Worker  *    void test18A()    - tests the assertion:
688*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
689*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
690*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_SLN as the third argument to the function fn if and only if the
691*49cdfc7eSAndroid Build Coastguard Worker  *      FTW_PHYS flag is not included in flags.
692*49cdfc7eSAndroid Build Coastguard Worker  */
693*49cdfc7eSAndroid Build Coastguard Worker 
test18A(void)694*49cdfc7eSAndroid Build Coastguard Worker void test18A(void)
695*49cdfc7eSAndroid Build Coastguard Worker {
696*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
697*49cdfc7eSAndroid Build Coastguard Worker 
698*49cdfc7eSAndroid Build Coastguard Worker 	unlink("./tmp/byebye");
699*49cdfc7eSAndroid Build Coastguard Worker 
700*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
701*49cdfc7eSAndroid Build Coastguard Worker 
702*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
703*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
704*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 with FTW_PHYS does not pass FTW_SLN\n");
705*49cdfc7eSAndroid Build Coastguard Worker #endif
706*49cdfc7eSAndroid Build Coastguard Worker 
707*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func18, MAX_FD, FTW_PHYS))
708*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
709*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
710*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
711*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
712*49cdfc7eSAndroid Build Coastguard Worker 	}
713*49cdfc7eSAndroid Build Coastguard Worker 	if (ret == 999) {
714*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: nftw64() passed FTW_SLN\n");
715*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
716*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
717*49cdfc7eSAndroid Build Coastguard Worker 	}
718*49cdfc7eSAndroid Build Coastguard Worker 
719*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
720*49cdfc7eSAndroid Build Coastguard Worker 
721*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
722*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: nftw64 without FTW_PHYS passes FTW_SLN\n");
723*49cdfc7eSAndroid Build Coastguard Worker #endif
724*49cdfc7eSAndroid Build Coastguard Worker 
725*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirg", test_func18, MAX_FD, 0)) == -1) {
726*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
727*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
728*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
729*49cdfc7eSAndroid Build Coastguard Worker 	}
730*49cdfc7eSAndroid Build Coastguard Worker 
731*49cdfc7eSAndroid Build Coastguard Worker 	if (visit == 1) {
732*49cdfc7eSAndroid Build Coastguard Worker 		if (ret == 999) {
733*49cdfc7eSAndroid Build Coastguard Worker 			/* Test is passed */
734*49cdfc7eSAndroid Build Coastguard Worker 			return;
735*49cdfc7eSAndroid Build Coastguard Worker 		} else {
736*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "ERROR: nftw64 passed FTW_SLN but did");
737*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "not return value returned by fn()\n");
738*49cdfc7eSAndroid Build Coastguard Worker 			cleanup_function();
739*49cdfc7eSAndroid Build Coastguard Worker 			fail_exit();
740*49cdfc7eSAndroid Build Coastguard Worker 		}
741*49cdfc7eSAndroid Build Coastguard Worker 	} else {
742*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: nftw64() did not pass FTW_SLN\n");
743*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
744*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
745*49cdfc7eSAndroid Build Coastguard Worker 	}
746*49cdfc7eSAndroid Build Coastguard Worker }
747*49cdfc7eSAndroid Build Coastguard Worker 
748*49cdfc7eSAndroid Build Coastguard Worker /*
749*49cdfc7eSAndroid Build Coastguard Worker  *    void test19A()    - tests the assertion:
750*49cdfc7eSAndroid Build Coastguard Worker  *      On a call to int nftw64(const char *path, int (*fn)(const char *, const
751*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when the
752*49cdfc7eSAndroid Build Coastguard Worker  *      third argument passed to the function fn is FTW_DNR then the
753*49cdfc7eSAndroid Build Coastguard Worker  *      descendants of the directory shall not be processed.
754*49cdfc7eSAndroid Build Coastguard Worker  */
755*49cdfc7eSAndroid Build Coastguard Worker 
test19A(void)756*49cdfc7eSAndroid Build Coastguard Worker void test19A(void)
757*49cdfc7eSAndroid Build Coastguard Worker {
758*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
759*49cdfc7eSAndroid Build Coastguard Worker 
760*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
761*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
762*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
763*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: Can not traverse directory with no read permission\n");
764*49cdfc7eSAndroid Build Coastguard Worker #endif
765*49cdfc7eSAndroid Build Coastguard Worker 
766*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
767*49cdfc7eSAndroid Build Coastguard Worker 
768*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = nftw64("./tmp/data/d333", test_func19, MAX_FD, 0);
769*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1) {
770*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
771*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
772*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
773*49cdfc7eSAndroid Build Coastguard Worker 	}
774*49cdfc7eSAndroid Build Coastguard Worker 
775*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == 999) {
776*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
777*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
778*49cdfc7eSAndroid Build Coastguard Worker 	}
779*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
780*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: fn only be called once\n");
781*49cdfc7eSAndroid Build Coastguard Worker #endif
782*49cdfc7eSAndroid Build Coastguard Worker 
783*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != 1) {
784*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: %s",
785*49cdfc7eSAndroid Build Coastguard Worker 			"Directory without read permission allows traversing\n");
786*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "       Visited %d files\n", visit);
787*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
788*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
789*49cdfc7eSAndroid Build Coastguard Worker 	}
790*49cdfc7eSAndroid Build Coastguard Worker }
791*49cdfc7eSAndroid Build Coastguard Worker 
792*49cdfc7eSAndroid Build Coastguard Worker /*
793*49cdfc7eSAndroid Build Coastguard Worker  *    void test20A()    - tests the assertion:
794*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
795*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall close
796*49cdfc7eSAndroid Build Coastguard Worker  *      any file descriptors or directory streams used to traverse the
797*49cdfc7eSAndroid Build Coastguard Worker  *      directory tree.
798*49cdfc7eSAndroid Build Coastguard Worker  */
799*49cdfc7eSAndroid Build Coastguard Worker 
test20A(void)800*49cdfc7eSAndroid Build Coastguard Worker void test20A(void)
801*49cdfc7eSAndroid Build Coastguard Worker {
802*49cdfc7eSAndroid Build Coastguard Worker 	int fd, nfd;
803*49cdfc7eSAndroid Build Coastguard Worker 
804*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
805*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
806*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: File descriptors used in traversal are closed\n");
807*49cdfc7eSAndroid Build Coastguard Worker #endif
808*49cdfc7eSAndroid Build Coastguard Worker 
809*49cdfc7eSAndroid Build Coastguard Worker 	if ((fd = open("./tmp/data/dirh", O_RDONLY)) == -1) {
810*49cdfc7eSAndroid Build Coastguard Worker 		perror("close");
811*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
812*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
813*49cdfc7eSAndroid Build Coastguard Worker 	}
814*49cdfc7eSAndroid Build Coastguard Worker 
815*49cdfc7eSAndroid Build Coastguard Worker 	if (close(fd) == -1) {
816*49cdfc7eSAndroid Build Coastguard Worker 		perror("close");
817*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
818*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
819*49cdfc7eSAndroid Build Coastguard Worker 	}
820*49cdfc7eSAndroid Build Coastguard Worker 
821*49cdfc7eSAndroid Build Coastguard Worker 	if (nftw64("./tmp/data/dirh", test_func20, 1, 0) == -1) {
822*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
823*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
824*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
825*49cdfc7eSAndroid Build Coastguard Worker 	}
826*49cdfc7eSAndroid Build Coastguard Worker 
827*49cdfc7eSAndroid Build Coastguard Worker 	if ((nfd = open("./tmp/data/dirh", O_RDONLY)) == -1) {
828*49cdfc7eSAndroid Build Coastguard Worker 		perror("open");
829*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
830*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
831*49cdfc7eSAndroid Build Coastguard Worker 	}
832*49cdfc7eSAndroid Build Coastguard Worker 
833*49cdfc7eSAndroid Build Coastguard Worker 	if (nfd != fd) {
834*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "ERROR: %s,fd == %d ofd = %d",
835*49cdfc7eSAndroid Build Coastguard Worker 			"nftw64 did not close all file descriptors used in traversal\n",
836*49cdfc7eSAndroid Build Coastguard Worker 			nfd, fd);
837*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
838*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
839*49cdfc7eSAndroid Build Coastguard Worker 	}
840*49cdfc7eSAndroid Build Coastguard Worker 
841*49cdfc7eSAndroid Build Coastguard Worker 	if (close(nfd) == -1) {
842*49cdfc7eSAndroid Build Coastguard Worker 		perror("close");
843*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
844*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
845*49cdfc7eSAndroid Build Coastguard Worker 	}
846*49cdfc7eSAndroid Build Coastguard Worker }
847*49cdfc7eSAndroid Build Coastguard Worker 
848*49cdfc7eSAndroid Build Coastguard Worker /*
849*49cdfc7eSAndroid Build Coastguard Worker  *    void test21A()    - tests the assertion:
850*49cdfc7eSAndroid Build Coastguard Worker  *      On a call to int nftw64(const char *path, int (*fn)(const char *, const
851*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall
852*49cdfc7eSAndroid Build Coastguard Worker  *      be the maximum number of file descriptors used for the search.
853*49cdfc7eSAndroid Build Coastguard Worker  */
854*49cdfc7eSAndroid Build Coastguard Worker 
test21A(void)855*49cdfc7eSAndroid Build Coastguard Worker void test21A(void)
856*49cdfc7eSAndroid Build Coastguard Worker {
857*49cdfc7eSAndroid Build Coastguard Worker 	char path[] = "./tmp/data/dirh";
858*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
859*49cdfc7eSAndroid Build Coastguard Worker 
860*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
861*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
862*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
863*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: No more than depth file descriptors used in traversal\n");
864*49cdfc7eSAndroid Build Coastguard Worker #endif
865*49cdfc7eSAndroid Build Coastguard Worker 
866*49cdfc7eSAndroid Build Coastguard Worker 	/*this is the fd we expect if 0 are used */
867*49cdfc7eSAndroid Build Coastguard Worker 	if ((next_fd[0] = open(path, O_RDONLY)) == -1) {
868*49cdfc7eSAndroid Build Coastguard Worker 		perror("open next_fd[0]");
869*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
870*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
871*49cdfc7eSAndroid Build Coastguard Worker 	}
872*49cdfc7eSAndroid Build Coastguard Worker 
873*49cdfc7eSAndroid Build Coastguard Worker 	/*this is the fd we expect if 1 is used */
874*49cdfc7eSAndroid Build Coastguard Worker 	if ((next_fd[1] = open(path, O_RDONLY)) == -1) {
875*49cdfc7eSAndroid Build Coastguard Worker 		perror("open next_fd[1]");
876*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
877*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
878*49cdfc7eSAndroid Build Coastguard Worker 	}
879*49cdfc7eSAndroid Build Coastguard Worker 
880*49cdfc7eSAndroid Build Coastguard Worker 	if (close(next_fd[0]) == -1) {
881*49cdfc7eSAndroid Build Coastguard Worker 		perror("close next_fd[0]");
882*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
883*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
884*49cdfc7eSAndroid Build Coastguard Worker 	}
885*49cdfc7eSAndroid Build Coastguard Worker 
886*49cdfc7eSAndroid Build Coastguard Worker 	if (close(next_fd[1]) == -1) {
887*49cdfc7eSAndroid Build Coastguard Worker 		perror("close next_fd[1]");
888*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
889*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
890*49cdfc7eSAndroid Build Coastguard Worker 	}
891*49cdfc7eSAndroid Build Coastguard Worker 
892*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
893*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = nftw64(path, test_func21, 1, 0);
894*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1) {
895*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
896*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
897*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
898*49cdfc7eSAndroid Build Coastguard Worker 	}
899*49cdfc7eSAndroid Build Coastguard Worker 
900*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == 999) {
901*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
902*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
903*49cdfc7eSAndroid Build Coastguard Worker 	}
904*49cdfc7eSAndroid Build Coastguard Worker }
905*49cdfc7eSAndroid Build Coastguard Worker 
906*49cdfc7eSAndroid Build Coastguard Worker /*
907*49cdfc7eSAndroid Build Coastguard Worker  *    void test22A()    - tests the assertion:
908*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
909*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) shall use at
910*49cdfc7eSAndroid Build Coastguard Worker  *      most one file descriptor for each directory level.
911*49cdfc7eSAndroid Build Coastguard Worker  */
912*49cdfc7eSAndroid Build Coastguard Worker 
test22A(void)913*49cdfc7eSAndroid Build Coastguard Worker void test22A(void)
914*49cdfc7eSAndroid Build Coastguard Worker {
915*49cdfc7eSAndroid Build Coastguard Worker 	char path[] = "./tmp/data/dirh";
916*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val, i;
917*49cdfc7eSAndroid Build Coastguard Worker 
918*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < 4; i++) {
919*49cdfc7eSAndroid Build Coastguard Worker 		if ((next_fd[i] = open(path, O_RDONLY)) == -1) {
920*49cdfc7eSAndroid Build Coastguard Worker 			perror("open");
921*49cdfc7eSAndroid Build Coastguard Worker 			cleanup_function();
922*49cdfc7eSAndroid Build Coastguard Worker 			fail_exit();
923*49cdfc7eSAndroid Build Coastguard Worker 		}
924*49cdfc7eSAndroid Build Coastguard Worker 	}
925*49cdfc7eSAndroid Build Coastguard Worker 
926*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < 4; i++) {
927*49cdfc7eSAndroid Build Coastguard Worker 		if (close(next_fd[i]) == -1) {
928*49cdfc7eSAndroid Build Coastguard Worker 			perror("close");
929*49cdfc7eSAndroid Build Coastguard Worker 			cleanup_function();
930*49cdfc7eSAndroid Build Coastguard Worker 			fail_exit();
931*49cdfc7eSAndroid Build Coastguard Worker 		}
932*49cdfc7eSAndroid Build Coastguard Worker 	}
933*49cdfc7eSAndroid Build Coastguard Worker 
934*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
935*49cdfc7eSAndroid Build Coastguard Worker 
936*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
937*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
938*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
939*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: No more than 1 fd per level is used in traversal\n");
940*49cdfc7eSAndroid Build Coastguard Worker #endif
941*49cdfc7eSAndroid Build Coastguard Worker 
942*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = nftw64(path, test_func22, MAX_FD, 0);
943*49cdfc7eSAndroid Build Coastguard Worker 
944*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1) {
945*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
946*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
947*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
948*49cdfc7eSAndroid Build Coastguard Worker 	}
949*49cdfc7eSAndroid Build Coastguard Worker 
950*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == 999) {
951*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
952*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
953*49cdfc7eSAndroid Build Coastguard Worker 	}
954*49cdfc7eSAndroid Build Coastguard Worker }
955*49cdfc7eSAndroid Build Coastguard Worker 
956*49cdfc7eSAndroid Build Coastguard Worker /*
957*49cdfc7eSAndroid Build Coastguard Worker  *    void test23A()    - tests the assertion:
958*49cdfc7eSAndroid Build Coastguard Worker  *      A call to int nftw64(const char *path, int (*fn)(const char *, const
959*49cdfc7eSAndroid Build Coastguard Worker  *      struct stat *, int, struct FTW *), int depth, int flags) when the
960*49cdfc7eSAndroid Build Coastguard Worker  *      function fn returns a non-zero value shall stop and return the value
961*49cdfc7eSAndroid Build Coastguard Worker  *      returned by fn.
962*49cdfc7eSAndroid Build Coastguard Worker  */
963*49cdfc7eSAndroid Build Coastguard Worker 
test23A(void)964*49cdfc7eSAndroid Build Coastguard Worker void test23A(void)
965*49cdfc7eSAndroid Build Coastguard Worker {
966*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
967*49cdfc7eSAndroid Build Coastguard Worker 
968*49cdfc7eSAndroid Build Coastguard Worker 	visit = 0;
969*49cdfc7eSAndroid Build Coastguard Worker 
970*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
971*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
972*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
973*49cdfc7eSAndroid Build Coastguard Worker 		"TEST: The function nftw64 should return with value set by fn\n");
974*49cdfc7eSAndroid Build Coastguard Worker #endif
975*49cdfc7eSAndroid Build Coastguard Worker 
976*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = nftw64("./tmp/data/dirh", test_func23, MAX_FD, FTW_PHYS))
977*49cdfc7eSAndroid Build Coastguard Worker 	    == -1) {
978*49cdfc7eSAndroid Build Coastguard Worker 		perror("nftw64");
979*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
980*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
981*49cdfc7eSAndroid Build Coastguard Worker 	}
982*49cdfc7eSAndroid Build Coastguard Worker 
983*49cdfc7eSAndroid Build Coastguard Worker 	if (ret != 999) {
984*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
985*49cdfc7eSAndroid Build Coastguard Worker 			"ERROR: nftw64 did not return value returned by fn()\n");
986*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
987*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
988*49cdfc7eSAndroid Build Coastguard Worker 	}
989*49cdfc7eSAndroid Build Coastguard Worker 	if (visit != 4) {
990*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
991*49cdfc7eSAndroid Build Coastguard Worker 			"ERROR: nftw64() did not return immediately on non-zero fn() return\n");
992*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
993*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
994*49cdfc7eSAndroid Build Coastguard Worker 	}
995*49cdfc7eSAndroid Build Coastguard Worker }
996*49cdfc7eSAndroid Build Coastguard Worker 
997*49cdfc7eSAndroid Build Coastguard Worker /*
998*49cdfc7eSAndroid Build Coastguard Worker  *    void test24A()    - tests the assertion:
999*49cdfc7eSAndroid Build Coastguard Worker  *      ENAMETOOLONG in errno and return -1 on a call to int nftw64(const char
1000*49cdfc7eSAndroid Build Coastguard Worker  *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
1001*49cdfc7eSAndroid Build Coastguard Worker  *      *), int depth, int flags) when the length of path exceeds PATH_MAX.
1002*49cdfc7eSAndroid Build Coastguard Worker  */
1003*49cdfc7eSAndroid Build Coastguard Worker 
test24A(void)1004*49cdfc7eSAndroid Build Coastguard Worker void test24A(void)
1005*49cdfc7eSAndroid Build Coastguard Worker {
1006*49cdfc7eSAndroid Build Coastguard Worker 	test_ENAMETOOLONG_path("nftw64", callback, -1);
1007*49cdfc7eSAndroid Build Coastguard Worker }
1008*49cdfc7eSAndroid Build Coastguard Worker 
1009*49cdfc7eSAndroid Build Coastguard Worker /*
1010*49cdfc7eSAndroid Build Coastguard Worker  *    void test25A()    - tests the assertion:
1011*49cdfc7eSAndroid Build Coastguard Worker  *      ENAMETOOLONG in errno and return -1 on a call to int nftw64(const char
1012*49cdfc7eSAndroid Build Coastguard Worker  *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
1013*49cdfc7eSAndroid Build Coastguard Worker  *      *), int depth, int flags) when a component of path exceeds NAME_MAX.
1014*49cdfc7eSAndroid Build Coastguard Worker  */
1015*49cdfc7eSAndroid Build Coastguard Worker 
test25A(void)1016*49cdfc7eSAndroid Build Coastguard Worker void test25A(void)
1017*49cdfc7eSAndroid Build Coastguard Worker {
1018*49cdfc7eSAndroid Build Coastguard Worker 	test_ENAMETOOLONG_name("nftw64", callback, -1);
1019*49cdfc7eSAndroid Build Coastguard Worker }
1020*49cdfc7eSAndroid Build Coastguard Worker 
1021*49cdfc7eSAndroid Build Coastguard Worker /*
1022*49cdfc7eSAndroid Build Coastguard Worker  *    void test26A()    - tests the assertion:
1023*49cdfc7eSAndroid Build Coastguard Worker  *      ENOENT in errno and return -1 on a call to int nftw64(const char *path,
1024*49cdfc7eSAndroid Build Coastguard Worker  *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1025*49cdfc7eSAndroid Build Coastguard Worker  *      depth, int flags) when path points to a file which does not exist.
1026*49cdfc7eSAndroid Build Coastguard Worker  */
1027*49cdfc7eSAndroid Build Coastguard Worker 
test26A(void)1028*49cdfc7eSAndroid Build Coastguard Worker void test26A(void)
1029*49cdfc7eSAndroid Build Coastguard Worker {
1030*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
1031*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1032*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: [ENOENT] && -1 returned by nftw64\n");
1033*49cdfc7eSAndroid Build Coastguard Worker #endif
1034*49cdfc7eSAndroid Build Coastguard Worker 
1035*49cdfc7eSAndroid Build Coastguard Worker 	test_ENOENT_nofile("nftw64", callback, -1);
1036*49cdfc7eSAndroid Build Coastguard Worker }
1037*49cdfc7eSAndroid Build Coastguard Worker 
1038*49cdfc7eSAndroid Build Coastguard Worker /*
1039*49cdfc7eSAndroid Build Coastguard Worker  *    void test27A()    - tests the assertion:
1040*49cdfc7eSAndroid Build Coastguard Worker  *      ENOENT in errno and return -1 on a call to int nftw64(const char *path,
1041*49cdfc7eSAndroid Build Coastguard Worker  *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1042*49cdfc7eSAndroid Build Coastguard Worker  *      depth, int flags) when path points to an empty string.
1043*49cdfc7eSAndroid Build Coastguard Worker  */
1044*49cdfc7eSAndroid Build Coastguard Worker 
test27A(void)1045*49cdfc7eSAndroid Build Coastguard Worker void test27A(void)
1046*49cdfc7eSAndroid Build Coastguard Worker {
1047*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
1048*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1049*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: The function nftw64 should return with a -1\n");
1050*49cdfc7eSAndroid Build Coastguard Worker #endif
1051*49cdfc7eSAndroid Build Coastguard Worker 
1052*49cdfc7eSAndroid Build Coastguard Worker 	test_ENOENT_empty("nftw64", callback, -1);
1053*49cdfc7eSAndroid Build Coastguard Worker }
1054*49cdfc7eSAndroid Build Coastguard Worker 
1055*49cdfc7eSAndroid Build Coastguard Worker /*
1056*49cdfc7eSAndroid Build Coastguard Worker  *    void test28A()    - tests the assertion:
1057*49cdfc7eSAndroid Build Coastguard Worker  *      ENOTDIR in errno and return -1 on a call to int nftw64(const char
1058*49cdfc7eSAndroid Build Coastguard Worker  *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
1059*49cdfc7eSAndroid Build Coastguard Worker  *      *), int depth, int flags) when path is not a directory.
1060*49cdfc7eSAndroid Build Coastguard Worker  */
1061*49cdfc7eSAndroid Build Coastguard Worker 
test28A(void)1062*49cdfc7eSAndroid Build Coastguard Worker void test28A(void)
1063*49cdfc7eSAndroid Build Coastguard Worker {
1064*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
1065*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1066*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: [ENOTDIR] && -1 returned by nftw64\n");
1067*49cdfc7eSAndroid Build Coastguard Worker #endif
1068*49cdfc7eSAndroid Build Coastguard Worker 
1069*49cdfc7eSAndroid Build Coastguard Worker 	test_ENOTDIR("nftw64", callback, -1);
1070*49cdfc7eSAndroid Build Coastguard Worker }
1071*49cdfc7eSAndroid Build Coastguard Worker 
1072*49cdfc7eSAndroid Build Coastguard Worker /*
1073*49cdfc7eSAndroid Build Coastguard Worker  *    void test29A()    - tests the assertion:
1074*49cdfc7eSAndroid Build Coastguard Worker  *      EACCES in errno and return -1 on a call to int nftw64(const char *path,
1075*49cdfc7eSAndroid Build Coastguard Worker  *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1076*49cdfc7eSAndroid Build Coastguard Worker  *      depth, int flags) when search permission is denied for any component
1077*49cdfc7eSAndroid Build Coastguard Worker  *      of path.
1078*49cdfc7eSAndroid Build Coastguard Worker  */
1079*49cdfc7eSAndroid Build Coastguard Worker 
test29A(void)1080*49cdfc7eSAndroid Build Coastguard Worker void test29A(void)
1081*49cdfc7eSAndroid Build Coastguard Worker {
1082*49cdfc7eSAndroid Build Coastguard Worker 	if (chmod("./tmp/data/d333", (mode_t) S_IRUSR) == -1) {
1083*49cdfc7eSAndroid Build Coastguard Worker 		perror("chmod");
1084*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
1085*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
1086*49cdfc7eSAndroid Build Coastguard Worker 	}
1087*49cdfc7eSAndroid Build Coastguard Worker 
1088*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
1089*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1090*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: [EACCES] && -1 returned by nftw64\n");
1091*49cdfc7eSAndroid Build Coastguard Worker #endif
1092*49cdfc7eSAndroid Build Coastguard Worker 
1093*49cdfc7eSAndroid Build Coastguard Worker 	test_ENOTDIR("nftw64", callback, -1);
1094*49cdfc7eSAndroid Build Coastguard Worker }
1095*49cdfc7eSAndroid Build Coastguard Worker 
1096*49cdfc7eSAndroid Build Coastguard Worker /*
1097*49cdfc7eSAndroid Build Coastguard Worker  *    void test30A()    - tests the assertion:
1098*49cdfc7eSAndroid Build Coastguard Worker  *      EACCES in errno and return -1 on a call to int nftw64(const char *path,
1099*49cdfc7eSAndroid Build Coastguard Worker  *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1100*49cdfc7eSAndroid Build Coastguard Worker  *      depth, int flags) when read permission is denied for path.
1101*49cdfc7eSAndroid Build Coastguard Worker  */
1102*49cdfc7eSAndroid Build Coastguard Worker 
test30A(void)1103*49cdfc7eSAndroid Build Coastguard Worker void test30A(void)
1104*49cdfc7eSAndroid Build Coastguard Worker {
1105*49cdfc7eSAndroid Build Coastguard Worker 	if (chmod("./tmp/data/d333", (mode_t) S_IXUSR) == -1) {
1106*49cdfc7eSAndroid Build Coastguard Worker 		perror("chmod");
1107*49cdfc7eSAndroid Build Coastguard Worker 		cleanup_function();
1108*49cdfc7eSAndroid Build Coastguard Worker 		fail_exit();
1109*49cdfc7eSAndroid Build Coastguard Worker 	}
1110*49cdfc7eSAndroid Build Coastguard Worker 
1111*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
1112*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
1113*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp, "TEST: [EACCES] && -1 returned by nftw64\n");
1114*49cdfc7eSAndroid Build Coastguard Worker #endif
1115*49cdfc7eSAndroid Build Coastguard Worker 
1116*49cdfc7eSAndroid Build Coastguard Worker 	test_ENOTDIR("nftw64", callback, -1);
1117*49cdfc7eSAndroid Build Coastguard Worker }
1118