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