1d45662739871a315e75b7d85a424531eb583cf79robbiew/*
2d45662739871a315e75b7d85a424531eb583cf79robbiew *
3d45662739871a315e75b7d85a424531eb583cf79robbiew *   Copyright (c) International Business Machines  Corp., 2002
4d45662739871a315e75b7d85a424531eb583cf79robbiew *
5d45662739871a315e75b7d85a424531eb583cf79robbiew *   This program is free software;  you can redistribute it and/or modify
6d45662739871a315e75b7d85a424531eb583cf79robbiew *   it under the terms of the GNU General Public License as published by
7d45662739871a315e75b7d85a424531eb583cf79robbiew *   the Free Software Foundation; either version 2 of the License, or
8d45662739871a315e75b7d85a424531eb583cf79robbiew *   (at your option) any later version.
9d45662739871a315e75b7d85a424531eb583cf79robbiew *
10d45662739871a315e75b7d85a424531eb583cf79robbiew *   This program is distributed in the hope that it will be useful,
11d45662739871a315e75b7d85a424531eb583cf79robbiew *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12d45662739871a315e75b7d85a424531eb583cf79robbiew *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13d45662739871a315e75b7d85a424531eb583cf79robbiew *   the GNU General Public License for more details.
14d45662739871a315e75b7d85a424531eb583cf79robbiew *
15d45662739871a315e75b7d85a424531eb583cf79robbiew *   You should have received a copy of the GNU General Public License
16d45662739871a315e75b7d85a424531eb583cf79robbiew *   along with this program;  if not, write to the Free Software
174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18d45662739871a315e75b7d85a424531eb583cf79robbiew */
19d45662739871a315e75b7d85a424531eb583cf79robbiew
20d45662739871a315e75b7d85a424531eb583cf79robbiew/* 10/31/2002   Port to LTP     robbiew@us.ibm.com */
21d45662739871a315e75b7d85a424531eb583cf79robbiew/* 06/30/2001   Port to Linux   nsharoff@us.ibm.com */
22d45662739871a315e75b7d85a424531eb583cf79robbiew
23d45662739871a315e75b7d85a424531eb583cf79robbiew/*
24d45662739871a315e75b7d85a424531eb583cf79robbiew * NAME
25d45662739871a315e75b7d85a424531eb583cf79robbiew *      test.c - Test functions for nftw()
26d45662739871a315e75b7d85a424531eb583cf79robbiew */
27d45662739871a315e75b7d85a424531eb583cf79robbiew
28d45662739871a315e75b7d85a424531eb583cf79robbiew#include "nftw.h"
29d45662739871a315e75b7d85a424531eb583cf79robbiew
30d45662739871a315e75b7d85a424531eb583cf79robbiewextern int callback(const char *path);
31d45662739871a315e75b7d85a424531eb583cf79robbiew
32d45662739871a315e75b7d85a424531eb583cf79robbiewextern pathdata pathdat[];
33d45662739871a315e75b7d85a424531eb583cf79robbiewextern struct list mnem[], badlist[];
34d45662739871a315e75b7d85a424531eb583cf79robbiewextern char *dirlist[NDIRLISTENTS], *goodlist[];
35d45662739871a315e75b7d85a424531eb583cf79robbiewextern int npathdats, ngoods, nbads, nmnem, visit, s2, next_fd[4];
36d45662739871a315e75b7d85a424531eb583cf79robbiew
377999352634e9294133c33b0f2eadb09c30a2d8a7vapierextern FILE *temp;
38d45662739871a315e75b7d85a424531eb583cf79robbiew/*
39d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test1A()     - tests the assertion:
40d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
41d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall
42d45662739871a315e75b7d85a424531eb583cf79robbiew *      recursively descend the directory hierarchy rooted in path until it
43d45662739871a315e75b7d85a424531eb583cf79robbiew *      has traversed the whole tree, calling the function fn for each object
44d45662739871a315e75b7d85a424531eb583cf79robbiew *      in the directory tree, and return 0.
45d45662739871a315e75b7d85a424531eb583cf79robbiew */
46d45662739871a315e75b7d85a424531eb583cf79robbiew
4756207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test1A(void)
48d45662739871a315e75b7d85a424531eb583cf79robbiew{
4956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int i, j, ret;
50d45662739871a315e75b7d85a424531eb583cf79robbiew
5156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	temp = stderr;
52d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
53d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw() succeeds\n");
54d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
55d45662739871a315e75b7d85a424531eb583cf79robbiew
56d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
5756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirh", test_func1, MAX_FD, 0)) == -1) {
58d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("ERROR: nftw failed");
59d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
60d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
61d45662739871a315e75b7d85a424531eb583cf79robbiew	}
62d45662739871a315e75b7d85a424531eb583cf79robbiew
6356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (ret == 999) {
64d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
65d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
66d45662739871a315e75b7d85a424531eb583cf79robbiew	}
67d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
68d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: Whole tree traversed\n");
69d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
70d45662739871a315e75b7d85a424531eb583cf79robbiew
71d45662739871a315e75b7d85a424531eb583cf79robbiew	if (visit != ngoods) {
72d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: Count of objects visited incorrect\n");
7356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp, "       Expected %d, Received %d\n", ngoods,
7456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			visit);
75d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
76d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
77d45662739871a315e75b7d85a424531eb583cf79robbiew	}
78d45662739871a315e75b7d85a424531eb583cf79robbiew
79d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < visit; i++) {
80d45662739871a315e75b7d85a424531eb583cf79robbiew		for (j = 0; j < ngoods; j++) {
81d45662739871a315e75b7d85a424531eb583cf79robbiew			if (strcmp(dirlist[i], goodlist[j]) == 0) {
82d45662739871a315e75b7d85a424531eb583cf79robbiew				free(dirlist[i]);
8345e285d46ab47b0ff76c88acb5ba97b0bd5f753dGarrett Cooper				dirlist[i] = NULL;
84d45662739871a315e75b7d85a424531eb583cf79robbiew				break;
85d45662739871a315e75b7d85a424531eb583cf79robbiew			}
86d45662739871a315e75b7d85a424531eb583cf79robbiew		}
87d45662739871a315e75b7d85a424531eb583cf79robbiew	}
88d45662739871a315e75b7d85a424531eb583cf79robbiew
89d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < visit; i++) {
9045e285d46ab47b0ff76c88acb5ba97b0bd5f753dGarrett Cooper		if (dirlist[i] != NULL) {
91d45662739871a315e75b7d85a424531eb583cf79robbiew			free(dirlist[i]);
9256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			fprintf(temp, "ERROR: Unexpected visit to %s\n",
9356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak				dirlist[i]);
94d45662739871a315e75b7d85a424531eb583cf79robbiew			cleanup_function();
95d45662739871a315e75b7d85a424531eb583cf79robbiew			fail_exit();
96d45662739871a315e75b7d85a424531eb583cf79robbiew		}
97d45662739871a315e75b7d85a424531eb583cf79robbiew	}
98d45662739871a315e75b7d85a424531eb583cf79robbiew}
99d45662739871a315e75b7d85a424531eb583cf79robbiew
100d45662739871a315e75b7d85a424531eb583cf79robbiew/*
101d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test2A()     - tests the assertion:
102d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
103d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when flags
104d45662739871a315e75b7d85a424531eb583cf79robbiew *      contains FTW_PHYS shall not traverse symbolic links.
105d45662739871a315e75b7d85a424531eb583cf79robbiew */
106d45662739871a315e75b7d85a424531eb583cf79robbiew
10756207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test2A(void)
108d45662739871a315e75b7d85a424531eb583cf79robbiew{
10956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int i, ret;
110d45662739871a315e75b7d85a424531eb583cf79robbiew
111d45662739871a315e75b7d85a424531eb583cf79robbiew	temp = stderr;
112d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
11356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
11456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw with FTW_PHYS does not follow symbolic links\n");
115d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
116d45662739871a315e75b7d85a424531eb583cf79robbiew
117d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
11856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirl", test_func1, MAX_FD, FTW_PHYS))
11956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	    == -1) {
120d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
121d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
122d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
123d45662739871a315e75b7d85a424531eb583cf79robbiew	}
124d45662739871a315e75b7d85a424531eb583cf79robbiew
12556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (ret == 999) {
126d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
127d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
128d45662739871a315e75b7d85a424531eb583cf79robbiew	}
129d45662739871a315e75b7d85a424531eb583cf79robbiew
13056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (visit != NO_LINK_CNT) {
13156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp,
13256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"ERROR: Expected %d files to be visited.  nftw() visited %d\n",
13356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			NO_LINK_CNT, visit);
134d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
135d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
136d45662739871a315e75b7d85a424531eb583cf79robbiew	}
137d45662739871a315e75b7d85a424531eb583cf79robbiew
138d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < visit; i++) {
13945e285d46ab47b0ff76c88acb5ba97b0bd5f753dGarrett Cooper		if (dirlist[i] != NULL)
140d45662739871a315e75b7d85a424531eb583cf79robbiew			free(dirlist[i]);
141d45662739871a315e75b7d85a424531eb583cf79robbiew	}
142d45662739871a315e75b7d85a424531eb583cf79robbiew}
143d45662739871a315e75b7d85a424531eb583cf79robbiew
144d45662739871a315e75b7d85a424531eb583cf79robbiew/*
145d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test3A()     - tests the assertion:
146d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
147d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when flags
148d45662739871a315e75b7d85a424531eb583cf79robbiew *      does not contain FTW_PHYS shall follow links instead of reporting
149d45662739871a315e75b7d85a424531eb583cf79robbiew *      them and shall not report the same file twice.
150d45662739871a315e75b7d85a424531eb583cf79robbiew */
151d45662739871a315e75b7d85a424531eb583cf79robbiew
15256207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test3A(void)
153d45662739871a315e75b7d85a424531eb583cf79robbiew{
15456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
155d45662739871a315e75b7d85a424531eb583cf79robbiew
156d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
157d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw without FTW_PHYS follows symbolic links\n");
158d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
159d45662739871a315e75b7d85a424531eb583cf79robbiew
160d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
161d45662739871a315e75b7d85a424531eb583cf79robbiew
16256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirl", test_func3, MAX_FD, 0)) == -1) {
163d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
164d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
165d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
166d45662739871a315e75b7d85a424531eb583cf79robbiew	}
16756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (ret == 999) {
168d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
169d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
170d45662739871a315e75b7d85a424531eb583cf79robbiew	}
171d45662739871a315e75b7d85a424531eb583cf79robbiew
17256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (visit != LINK_CNT - 1) {
17356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp,
17456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"ERROR: Expected %d files to be visited.  nftw() visited %d\n",
17556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			LINK_CNT - 1, visit);
1764bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak		cleanup_function();
177d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
178d45662739871a315e75b7d85a424531eb583cf79robbiew	}
179d45662739871a315e75b7d85a424531eb583cf79robbiew}
180d45662739871a315e75b7d85a424531eb583cf79robbiew
181d45662739871a315e75b7d85a424531eb583cf79robbiew/*
182d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test4A()     - tests the assertion:
183d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
184d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when flags
185d45662739871a315e75b7d85a424531eb583cf79robbiew *      contains FTW_DEPTH shall report all files in a directory before
186d45662739871a315e75b7d85a424531eb583cf79robbiew *      reporting the directory.
187d45662739871a315e75b7d85a424531eb583cf79robbiew */
188d45662739871a315e75b7d85a424531eb583cf79robbiew
18956207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test4A(void)
190d45662739871a315e75b7d85a424531eb583cf79robbiew{
19156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[] = "./tmp/data/d777";
19256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val;
193d45662739871a315e75b7d85a424531eb583cf79robbiew
194d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
195d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: Verify traversal with FTW_DEPTH set\n");
196d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
197d45662739871a315e75b7d85a424531eb583cf79robbiew
198d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
19956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret_val = nftw(path, test_func4, MAX_FD, FTW_DEPTH)) == -1) {
200d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
201d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
202d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
203d45662739871a315e75b7d85a424531eb583cf79robbiew	}
20456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (ret_val != 999) {
205d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: %s never visited\n", path);
206d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
207d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
208d45662739871a315e75b7d85a424531eb583cf79robbiew	}
209d45662739871a315e75b7d85a424531eb583cf79robbiew
210d45662739871a315e75b7d85a424531eb583cf79robbiew	if (visit != 2) {
211d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: Visited directory before contents\n");
212d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
213d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
214d45662739871a315e75b7d85a424531eb583cf79robbiew	}
215d45662739871a315e75b7d85a424531eb583cf79robbiew}
216d45662739871a315e75b7d85a424531eb583cf79robbiew
217d45662739871a315e75b7d85a424531eb583cf79robbiew/*
218d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test5A()     - tests the assertion:
219d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
220d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when flags
221d45662739871a315e75b7d85a424531eb583cf79robbiew *      does not contain FTW_DEPTH shall report a directory before reporting
222d45662739871a315e75b7d85a424531eb583cf79robbiew *      the files in that directory.
223d45662739871a315e75b7d85a424531eb583cf79robbiew */
224d45662739871a315e75b7d85a424531eb583cf79robbiew
22556207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test5A(void)
226d45662739871a315e75b7d85a424531eb583cf79robbiew{
22756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[] = "./tmp/data/d777";
22856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val;
229d45662739871a315e75b7d85a424531eb583cf79robbiew
230d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
231d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: Verify traversal without FTW_DEPTH set\n");
232d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
233d45662739871a315e75b7d85a424531eb583cf79robbiew
234d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
23556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret_val = nftw(path, test_func4, MAX_FD, 0)) == -1) {
236d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
237d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
238d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
239d45662739871a315e75b7d85a424531eb583cf79robbiew	}
24056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (ret_val != 999) {
241d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: %s never visited\n", path);
242d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
243d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
244d45662739871a315e75b7d85a424531eb583cf79robbiew	}
245d45662739871a315e75b7d85a424531eb583cf79robbiew
24656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (visit != 1) {
247d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: Visited contents before directory\n");
248d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
249d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
250d45662739871a315e75b7d85a424531eb583cf79robbiew	}
251d45662739871a315e75b7d85a424531eb583cf79robbiew}
252d45662739871a315e75b7d85a424531eb583cf79robbiew
253d45662739871a315e75b7d85a424531eb583cf79robbiew/*
254d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test6A()     - tests the assertion:
255d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
256d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when flags
257d45662739871a315e75b7d85a424531eb583cf79robbiew *      contains FTW_CHDIR shall change the current working directory to each
258d45662739871a315e75b7d85a424531eb583cf79robbiew *      directory as it reports files in that directory.
259d45662739871a315e75b7d85a424531eb583cf79robbiew */
260d45662739871a315e75b7d85a424531eb583cf79robbiew
26156207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test6A(void)
262d45662739871a315e75b7d85a424531eb583cf79robbiew{
26356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[PATH_MAX + NAME_MAX];
26456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val;
265d45662739871a315e75b7d85a424531eb583cf79robbiew
26656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (getcwd(path, sizeof(path)) == NULL) {
267d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("getcwd");
268d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
269d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
270d45662739871a315e75b7d85a424531eb583cf79robbiew	}
271d45662739871a315e75b7d85a424531eb583cf79robbiew	(void)strcat(path, "/tmp/data/dirh");
272d45662739871a315e75b7d85a424531eb583cf79robbiew
273d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
27456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
27556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw with FTW_CHDIR changes to each dir before reporting files in it\n");
276d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
277d45662739871a315e75b7d85a424531eb583cf79robbiew
278d45662739871a315e75b7d85a424531eb583cf79robbiew	ret_val = nftw(path, test_func5, MAX_FD, FTW_CHDIR);
279d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == -1) {
280d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
281d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
282d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
283d45662739871a315e75b7d85a424531eb583cf79robbiew	}
284d45662739871a315e75b7d85a424531eb583cf79robbiew	if ((ret_val == 998) || (ret_val == 999)) {
285d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
286d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
287d45662739871a315e75b7d85a424531eb583cf79robbiew	}
288d45662739871a315e75b7d85a424531eb583cf79robbiew}
289d45662739871a315e75b7d85a424531eb583cf79robbiew
290d45662739871a315e75b7d85a424531eb583cf79robbiew/*
291d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test7A()     - tests the assertion:
292d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
293d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
294d45662739871a315e75b7d85a424531eb583cf79robbiew *      the path-name of the current object as the first argument of the
295d45662739871a315e75b7d85a424531eb583cf79robbiew *      function fn.
296d45662739871a315e75b7d85a424531eb583cf79robbiew */
297d45662739871a315e75b7d85a424531eb583cf79robbiew
29856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test7A(void)
299d45662739871a315e75b7d85a424531eb583cf79robbiew{
30056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
301d45662739871a315e75b7d85a424531eb583cf79robbiew
302d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
303d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw passes pathname as first argument to fn()\n");
304d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
305d45662739871a315e75b7d85a424531eb583cf79robbiew
30656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func7, MAX_FD, 0)) == -1) {
307d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
308d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
309d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
310d45662739871a315e75b7d85a424531eb583cf79robbiew	}
311d45662739871a315e75b7d85a424531eb583cf79robbiew
312d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
313d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
314d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
315d45662739871a315e75b7d85a424531eb583cf79robbiew	}
316d45662739871a315e75b7d85a424531eb583cf79robbiew}
317d45662739871a315e75b7d85a424531eb583cf79robbiew
318d45662739871a315e75b7d85a424531eb583cf79robbiew/*
319d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test8A()    - tests the assertion:
320d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
321d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass a
322d45662739871a315e75b7d85a424531eb583cf79robbiew *      pointer to a stat structure containing information about the current
323d45662739871a315e75b7d85a424531eb583cf79robbiew *      object as the second argument to fn.
324d45662739871a315e75b7d85a424531eb583cf79robbiew */
325d45662739871a315e75b7d85a424531eb583cf79robbiew
32656207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test8A(void)
327d45662739871a315e75b7d85a424531eb583cf79robbiew{
32856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
329d45662739871a315e75b7d85a424531eb583cf79robbiew
330d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
33156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
33256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw passes stat struct as second argument to fn()\n");
333d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
334d45662739871a315e75b7d85a424531eb583cf79robbiew
33556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func8, MAX_FD, 0)) == -1) {
336d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
337d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
338d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
339d45662739871a315e75b7d85a424531eb583cf79robbiew	}
340d45662739871a315e75b7d85a424531eb583cf79robbiew
341d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
342d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
343d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
344d45662739871a315e75b7d85a424531eb583cf79robbiew	}
345d45662739871a315e75b7d85a424531eb583cf79robbiew}
346d45662739871a315e75b7d85a424531eb583cf79robbiew
347d45662739871a315e75b7d85a424531eb583cf79robbiew/*
348d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test9A()    - tests the assertion:
349d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
350d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
351d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_F as the third argument of the function fn when the object is a
352d45662739871a315e75b7d85a424531eb583cf79robbiew *      file
353d45662739871a315e75b7d85a424531eb583cf79robbiew */
354d45662739871a315e75b7d85a424531eb583cf79robbiew
35556207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test9A(void)
356d45662739871a315e75b7d85a424531eb583cf79robbiew{
35756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
358d45662739871a315e75b7d85a424531eb583cf79robbiew
359d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
36056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
36156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw passes FTW_F as third arg to fn() for files\n");
362d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
363d45662739871a315e75b7d85a424531eb583cf79robbiew
36456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func9, MAX_FD, FTW_PHYS)) == -1) {
365d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
366d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
367d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
368d45662739871a315e75b7d85a424531eb583cf79robbiew	}
369d45662739871a315e75b7d85a424531eb583cf79robbiew
370d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
371d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
372d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
373d45662739871a315e75b7d85a424531eb583cf79robbiew	}
374d45662739871a315e75b7d85a424531eb583cf79robbiew}
375d45662739871a315e75b7d85a424531eb583cf79robbiew
376d45662739871a315e75b7d85a424531eb583cf79robbiew/*
377d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test10A()    - tests the assertion:
378d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
379d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
380d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_D as the third argument of the function fn when the object is a
381d45662739871a315e75b7d85a424531eb583cf79robbiew *      directory.
382d45662739871a315e75b7d85a424531eb583cf79robbiew */
383d45662739871a315e75b7d85a424531eb583cf79robbiew
38456207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test10A(void)
385d45662739871a315e75b7d85a424531eb583cf79robbiew{
38656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
387d45662739871a315e75b7d85a424531eb583cf79robbiew
388d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
38956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
39056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw passes FTW_D as third arg to fn() when file is directory\n");
391d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
392d45662739871a315e75b7d85a424531eb583cf79robbiew
3934bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func10, MAX_FD,
394d45662739871a315e75b7d85a424531eb583cf79robbiew			FTW_PHYS)) == -1) {
395d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
396d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
397d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
398d45662739871a315e75b7d85a424531eb583cf79robbiew	}
399d45662739871a315e75b7d85a424531eb583cf79robbiew
400d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
401d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
402d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
403d45662739871a315e75b7d85a424531eb583cf79robbiew	}
404d45662739871a315e75b7d85a424531eb583cf79robbiew}
405d45662739871a315e75b7d85a424531eb583cf79robbiew
406d45662739871a315e75b7d85a424531eb583cf79robbiew/*
407d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test11A()    - tests the assertion:
408d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
409d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
410d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_DP as the third argument of the function fn when the object is a
411d45662739871a315e75b7d85a424531eb583cf79robbiew *      directory and subdirectories have been visited.
412d45662739871a315e75b7d85a424531eb583cf79robbiew */
413d45662739871a315e75b7d85a424531eb583cf79robbiew
41456207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test11A(void)
415d45662739871a315e75b7d85a424531eb583cf79robbiew{
41656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int i, ret;
417d45662739871a315e75b7d85a424531eb583cf79robbiew
418d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < nbads; i++)
419d45662739871a315e75b7d85a424531eb583cf79robbiew		if (badlist[i].i == FTW_D)
420d45662739871a315e75b7d85a424531eb583cf79robbiew			badlist[i].i = FTW_DP;
421d45662739871a315e75b7d85a424531eb583cf79robbiew
422d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
42356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
42456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw passes FTW_DP when file is directory and subdirs already visited\n");
425d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
426d45662739871a315e75b7d85a424531eb583cf79robbiew
42756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func11, MAX_FD, FTW_DEPTH |
428d45662739871a315e75b7d85a424531eb583cf79robbiew			FTW_PHYS)) == -1) {
429d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
430d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
431d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
432d45662739871a315e75b7d85a424531eb583cf79robbiew	}
433d45662739871a315e75b7d85a424531eb583cf79robbiew
434d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
435d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
436d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
437d45662739871a315e75b7d85a424531eb583cf79robbiew	}
438d45662739871a315e75b7d85a424531eb583cf79robbiew}
439d45662739871a315e75b7d85a424531eb583cf79robbiew
440d45662739871a315e75b7d85a424531eb583cf79robbiew/*
441d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test12A()    - tests the assertion:
442d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
443d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
444d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_SL as the third argument of the function fn when the object is a
445d45662739871a315e75b7d85a424531eb583cf79robbiew *      symbolic link.
446d45662739871a315e75b7d85a424531eb583cf79robbiew */
447d45662739871a315e75b7d85a424531eb583cf79robbiew
44856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test12A(void)
449d45662739871a315e75b7d85a424531eb583cf79robbiew{
45056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
451d45662739871a315e75b7d85a424531eb583cf79robbiew
452d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
4534bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	fprintf(temp,
454d45662739871a315e75b7d85a424531eb583cf79robbiew		"TEST: nftw wth FTW_PHYS passes FTW_SL when file is symlink\n");
455d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
456d45662739871a315e75b7d85a424531eb583cf79robbiew
45756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func12, MAX_FD,
458d45662739871a315e75b7d85a424531eb583cf79robbiew			FTW_PHYS)) == -1) {
459d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
460d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
461d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
462d45662739871a315e75b7d85a424531eb583cf79robbiew	}
463d45662739871a315e75b7d85a424531eb583cf79robbiew
464d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
465d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
466d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
467d45662739871a315e75b7d85a424531eb583cf79robbiew	}
468d45662739871a315e75b7d85a424531eb583cf79robbiew}
469d45662739871a315e75b7d85a424531eb583cf79robbiew
470d45662739871a315e75b7d85a424531eb583cf79robbiew/*
471d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test13A()    - tests the assertion:
472d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
473d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
474d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_SLN as the third argument of the function fn when the object is a
475d45662739871a315e75b7d85a424531eb583cf79robbiew *      symbolic link that does not name an existing file.
476d45662739871a315e75b7d85a424531eb583cf79robbiew */
477d45662739871a315e75b7d85a424531eb583cf79robbiew
47856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test13A(void)
479d45662739871a315e75b7d85a424531eb583cf79robbiew{
48056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int i, ret;
481d45662739871a315e75b7d85a424531eb583cf79robbiew
48256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (unlink("./tmp/byebye") == -1) {
483d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("unlink");
484d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
485bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak		fail_exit();
486d45662739871a315e75b7d85a424531eb583cf79robbiew	}
487d45662739871a315e75b7d85a424531eb583cf79robbiew
488d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < nbads; i++)
489d45662739871a315e75b7d85a424531eb583cf79robbiew		if (badlist[i].i == FTW_SL)
490d45662739871a315e75b7d85a424531eb583cf79robbiew			badlist[i].i = FTW_SLN;
491d45662739871a315e75b7d85a424531eb583cf79robbiew
492d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
493d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw with FTW_PHYS passes FTW_SLN when file");
494d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, " is symlink pointing \n to non-existent file\n");
495d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
496d45662739871a315e75b7d85a424531eb583cf79robbiew
49756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func13, MAX_FD,
498d45662739871a315e75b7d85a424531eb583cf79robbiew			FTW_PHYS)) == -1) {
499d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
500d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
501d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
502d45662739871a315e75b7d85a424531eb583cf79robbiew	}
503d45662739871a315e75b7d85a424531eb583cf79robbiew
504d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
505d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
506d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
507d45662739871a315e75b7d85a424531eb583cf79robbiew	}
508d45662739871a315e75b7d85a424531eb583cf79robbiew}
509d45662739871a315e75b7d85a424531eb583cf79robbiew
510d45662739871a315e75b7d85a424531eb583cf79robbiew/*
511d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test14A()    - tests the assertion:
512d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
513d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
514d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_DNR as the third argument of the function fn when the object is a
515d45662739871a315e75b7d85a424531eb583cf79robbiew *      directory that cannot be read.
516d45662739871a315e75b7d85a424531eb583cf79robbiew */
517d45662739871a315e75b7d85a424531eb583cf79robbiew
51856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test14A(void)
519d45662739871a315e75b7d85a424531eb583cf79robbiew{
52056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
521d45662739871a315e75b7d85a424531eb583cf79robbiew
522d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
52356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
52456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw passes FTW_DNR when file is directory that cannot be read\n");
525d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
526d45662739871a315e75b7d85a424531eb583cf79robbiew
52756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/d333", test_func14, MAX_FD, 0)) == -1) {
528d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
529d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
530d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
531d45662739871a315e75b7d85a424531eb583cf79robbiew	}
532d45662739871a315e75b7d85a424531eb583cf79robbiew
533d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
534d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
535d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
536d45662739871a315e75b7d85a424531eb583cf79robbiew	}
537d45662739871a315e75b7d85a424531eb583cf79robbiew}
538d45662739871a315e75b7d85a424531eb583cf79robbiew
539d45662739871a315e75b7d85a424531eb583cf79robbiew/*
540d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test15A()    - tests the assertion:
541d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
542d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
543d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_NS as the third argument of the function fn when stat() failed on
544d45662739871a315e75b7d85a424531eb583cf79robbiew *      the object because of lack of appropriate permission.
545d45662739871a315e75b7d85a424531eb583cf79robbiew */
546d45662739871a315e75b7d85a424531eb583cf79robbiew
54756207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test15A(void)
548d45662739871a315e75b7d85a424531eb583cf79robbiew{
54956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
550d45662739871a315e75b7d85a424531eb583cf79robbiew
551d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
55256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
55356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw(path, fn, depth, FTW_PHYS) passes FTW_NS when dir unsearchable\n");
554d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
555d45662739871a315e75b7d85a424531eb583cf79robbiew
55656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret =
55756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	     nftw("./tmp/data/d666", test_func15, MAX_FD, FTW_PHYS)) == -1) {
558d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
559d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
560d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
561d45662739871a315e75b7d85a424531eb583cf79robbiew	}
562d45662739871a315e75b7d85a424531eb583cf79robbiew
563d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
564d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
565d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
566d45662739871a315e75b7d85a424531eb583cf79robbiew	}
567d45662739871a315e75b7d85a424531eb583cf79robbiew}
568d45662739871a315e75b7d85a424531eb583cf79robbiew
569d45662739871a315e75b7d85a424531eb583cf79robbiew/*
570d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test16A()    - tests the assertion:
571d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
572d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass a
573d45662739871a315e75b7d85a424531eb583cf79robbiew *      structure which contains the offset into the pathname of the object
574d45662739871a315e75b7d85a424531eb583cf79robbiew *      and the depth relative to the root of the walk starting from 0 as the
575d45662739871a315e75b7d85a424531eb583cf79robbiew *      fourth argument of the function fn.
576d45662739871a315e75b7d85a424531eb583cf79robbiew */
577d45662739871a315e75b7d85a424531eb583cf79robbiew
57856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test16A(void)
579d45662739871a315e75b7d85a424531eb583cf79robbiew{
58056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[PATH_MAX + NAME_MAX];
58156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char orig[PATH_MAX];
582d45662739871a315e75b7d85a424531eb583cf79robbiew
58356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (getcwd(orig, sizeof(orig)) == NULL) {
584d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("getcwd on original wd");
585d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
586d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
587d45662739871a315e75b7d85a424531eb583cf79robbiew	}
588d45662739871a315e75b7d85a424531eb583cf79robbiew
589d45662739871a315e75b7d85a424531eb583cf79robbiew	strcpy(path, orig);
590d45662739871a315e75b7d85a424531eb583cf79robbiew	(void)strcat(path, "/tmp/data/dirg");
591d45662739871a315e75b7d85a424531eb583cf79robbiew
592d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
593d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw with absolute pathname %s\n", path);
594d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
595d45662739871a315e75b7d85a424531eb583cf79robbiew
59656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((s2 = nftw(path, test_func16, MAX_FD, 0)) == -1) {
597d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
598d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
599d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
600d45662739871a315e75b7d85a424531eb583cf79robbiew	}
601d45662739871a315e75b7d85a424531eb583cf79robbiew	if (s2 == 999) {
602d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
603d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
604d45662739871a315e75b7d85a424531eb583cf79robbiew	}
605d45662739871a315e75b7d85a424531eb583cf79robbiew
606d45662739871a315e75b7d85a424531eb583cf79robbiew	(void)strcpy(path, "./tmp/data/dirg");
607d45662739871a315e75b7d85a424531eb583cf79robbiew
608d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
609d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw with relative pathname %s\n", path);
610d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
611d45662739871a315e75b7d85a424531eb583cf79robbiew
61256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((s2 = nftw(path, test_func16, MAX_FD, 0)) == -1) {
613d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
614d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
615d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
616d45662739871a315e75b7d85a424531eb583cf79robbiew	}
617d45662739871a315e75b7d85a424531eb583cf79robbiew
618d45662739871a315e75b7d85a424531eb583cf79robbiew	if (s2 == 999) {
619d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
620d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
621d45662739871a315e75b7d85a424531eb583cf79robbiew	}
622d45662739871a315e75b7d85a424531eb583cf79robbiew}
623d45662739871a315e75b7d85a424531eb583cf79robbiew
624d45662739871a315e75b7d85a424531eb583cf79robbiew/*
625d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test17A()    - tests the assertion:
626d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
627d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
628d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_SL as the third argument to the function fn if and only if the
629d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_PHYS flag is included in flags.
630d45662739871a315e75b7d85a424531eb583cf79robbiew */
631d45662739871a315e75b7d85a424531eb583cf79robbiew
63256207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test17A(void)
633d45662739871a315e75b7d85a424531eb583cf79robbiew{
63456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
635d45662739871a315e75b7d85a424531eb583cf79robbiew
636d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
637d45662739871a315e75b7d85a424531eb583cf79robbiew
638d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
639d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw with FTW_PHYS passes FTW_SL for symlink\n");
640d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
641d45662739871a315e75b7d85a424531eb583cf79robbiew
64256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret =
64356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	     nftw("./tmp/data/dirl", test_func17, MAX_FD, FTW_PHYS)) == -1) {
644d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
645d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
646d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
647d45662739871a315e75b7d85a424531eb583cf79robbiew	}
648d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret != 999) {
649d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: nftw() failed to find symbolic link\n");
650d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
651d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
652d45662739871a315e75b7d85a424531eb583cf79robbiew	}
653d45662739871a315e75b7d85a424531eb583cf79robbiew
654d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
655d45662739871a315e75b7d85a424531eb583cf79robbiew
656d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
65756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
65856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: nftw without FTW_PHYS does not pass FTW_SL for symlink\n");
659d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
660d45662739871a315e75b7d85a424531eb583cf79robbiew
66156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirl", test_func17, MAX_FD, 0)) == -1) {
662d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
663d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
664d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
665d45662739871a315e75b7d85a424531eb583cf79robbiew	}
666d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
667d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: nftw() found symbolic link\n");
668d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
669d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
670d45662739871a315e75b7d85a424531eb583cf79robbiew	}
671d45662739871a315e75b7d85a424531eb583cf79robbiew}
672d45662739871a315e75b7d85a424531eb583cf79robbiew
673d45662739871a315e75b7d85a424531eb583cf79robbiew/*
674d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test18A()    - tests the assertion:
675d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
676d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall pass
677d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_SLN as the third argument to the function fn if and only if the
678d45662739871a315e75b7d85a424531eb583cf79robbiew *      FTW_PHYS flag is not included in flags.
679d45662739871a315e75b7d85a424531eb583cf79robbiew */
680d45662739871a315e75b7d85a424531eb583cf79robbiew
68156207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test18A(void)
682d45662739871a315e75b7d85a424531eb583cf79robbiew{
68356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
684d45662739871a315e75b7d85a424531eb583cf79robbiew
685d45662739871a315e75b7d85a424531eb583cf79robbiew	unlink("./tmp/byebye");
686d45662739871a315e75b7d85a424531eb583cf79robbiew
68756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	visit = 0;
688d45662739871a315e75b7d85a424531eb583cf79robbiew
689d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
690d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw with FTW_PHYS does not pass FTW_SLN\n");
691d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
692d45662739871a315e75b7d85a424531eb583cf79robbiew
69356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func18, MAX_FD,
694d45662739871a315e75b7d85a424531eb583cf79robbiew			FTW_PHYS)) == -1) {
695d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
696d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
697d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
698d45662739871a315e75b7d85a424531eb583cf79robbiew	}
699d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret == 999) {
700d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: nftw() passed FTW_SLN\n");
701d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
702d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
703d45662739871a315e75b7d85a424531eb583cf79robbiew	}
704d45662739871a315e75b7d85a424531eb583cf79robbiew
70556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	visit = 0;
706d45662739871a315e75b7d85a424531eb583cf79robbiew
707d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
708d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: nftw without FTW_PHYS passes FTW_SLN\n");
709d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
710d45662739871a315e75b7d85a424531eb583cf79robbiew
71156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret = nftw("./tmp/data/dirg", test_func18, MAX_FD, 0)) == -1) {
712d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
713d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
714d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
715d45662739871a315e75b7d85a424531eb583cf79robbiew	}
716bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak
717d45662739871a315e75b7d85a424531eb583cf79robbiew	if (visit == 1) {
718d45662739871a315e75b7d85a424531eb583cf79robbiew		if (ret == 999) {
719d45662739871a315e75b7d85a424531eb583cf79robbiew			/* Test is passed */
720d45662739871a315e75b7d85a424531eb583cf79robbiew			return;
7214bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak		} else {
7224bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak			fprintf(temp, "ERROR: nftw passed FTW_SLN but did");
723d45662739871a315e75b7d85a424531eb583cf79robbiew			fprintf(temp, "not return value returned by fn()\n");
724d45662739871a315e75b7d85a424531eb583cf79robbiew			cleanup_function();
725d45662739871a315e75b7d85a424531eb583cf79robbiew			fail_exit();
726d45662739871a315e75b7d85a424531eb583cf79robbiew		}
727d45662739871a315e75b7d85a424531eb583cf79robbiew	} else {
728d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "ERROR: nftw() did not pass FTW_SLN\n");
729d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
730d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
731d45662739871a315e75b7d85a424531eb583cf79robbiew	}
732d45662739871a315e75b7d85a424531eb583cf79robbiew}
733d45662739871a315e75b7d85a424531eb583cf79robbiew
734d45662739871a315e75b7d85a424531eb583cf79robbiew/*
735d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test19A()    - tests the assertion:
736d45662739871a315e75b7d85a424531eb583cf79robbiew *      On a call to int nftw(const char *path, int (*fn)(const char *, const
737d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when the
738d45662739871a315e75b7d85a424531eb583cf79robbiew *      third argument passed to the function fn is FTW_DNR then the
739d45662739871a315e75b7d85a424531eb583cf79robbiew *      descendants of the directory shall not be processed.
740d45662739871a315e75b7d85a424531eb583cf79robbiew */
741d45662739871a315e75b7d85a424531eb583cf79robbiew
74256207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test19A(void)
743d45662739871a315e75b7d85a424531eb583cf79robbiew{
74456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val;
745d45662739871a315e75b7d85a424531eb583cf79robbiew
746d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
74756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
74856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: Can not traverse directory with no read permission\n");
749d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
750d45662739871a315e75b7d85a424531eb583cf79robbiew
751d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
752d45662739871a315e75b7d85a424531eb583cf79robbiew
753d45662739871a315e75b7d85a424531eb583cf79robbiew	ret_val = nftw("./tmp/data/d333", test_func19, MAX_FD, 0);
754d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == -1) {
755d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
756d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
757d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
758d45662739871a315e75b7d85a424531eb583cf79robbiew	}
759d45662739871a315e75b7d85a424531eb583cf79robbiew
760d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == 999) {
761d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
762d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
763d45662739871a315e75b7d85a424531eb583cf79robbiew	}
764d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
765d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: fn only be called once\n");
766d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
767d45662739871a315e75b7d85a424531eb583cf79robbiew
76856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (visit != 1) {
76956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp, "ERROR: %s",
77056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"Directory without read permission allows traversing\n");
771d45662739871a315e75b7d85a424531eb583cf79robbiew		fprintf(temp, "       Visited %d files\n", visit);
772d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
773d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
774d45662739871a315e75b7d85a424531eb583cf79robbiew	}
775d45662739871a315e75b7d85a424531eb583cf79robbiew}
776d45662739871a315e75b7d85a424531eb583cf79robbiew
777d45662739871a315e75b7d85a424531eb583cf79robbiew/*
778d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test20A()    - tests the assertion:
779d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
780d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall close
781d45662739871a315e75b7d85a424531eb583cf79robbiew *      any file descriptors or directory streams used to traverse the
782d45662739871a315e75b7d85a424531eb583cf79robbiew *      directory tree.
783d45662739871a315e75b7d85a424531eb583cf79robbiew */
784d45662739871a315e75b7d85a424531eb583cf79robbiew
78556207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test20A(void)
786d45662739871a315e75b7d85a424531eb583cf79robbiew{
78756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int fd, nfd;
788d45662739871a315e75b7d85a424531eb583cf79robbiew
789d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
790d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: File descriptors used in traversal are closed\n");
791d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
792d45662739871a315e75b7d85a424531eb583cf79robbiew
79356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((fd = open("./tmp/data/dirh", O_RDONLY)) == -1) {
794d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("close");
795d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
796d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
797d45662739871a315e75b7d85a424531eb583cf79robbiew	}
798d45662739871a315e75b7d85a424531eb583cf79robbiew
79956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (close(fd) == -1) {
800d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("close");
801d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
802d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
803d45662739871a315e75b7d85a424531eb583cf79robbiew	}
804d45662739871a315e75b7d85a424531eb583cf79robbiew
80556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (nftw("./tmp/data/dirh", test_func20, 1, 0) == -1) {
806d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
807d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
808d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
809d45662739871a315e75b7d85a424531eb583cf79robbiew	}
810d45662739871a315e75b7d85a424531eb583cf79robbiew
81156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((nfd = open("./tmp/data/dirh", O_RDONLY)) == -1) {
812d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("open");
813d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
814d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
815d45662739871a315e75b7d85a424531eb583cf79robbiew	}
816d45662739871a315e75b7d85a424531eb583cf79robbiew
817d45662739871a315e75b7d85a424531eb583cf79robbiew	if (nfd != fd) {
81856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp, "ERROR: %s,fd == %d ofd = %d",
81956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"nftw did not close all file descriptors used in traversal\n",
82056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			nfd, fd);
821d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
822d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
823d45662739871a315e75b7d85a424531eb583cf79robbiew	}
824d45662739871a315e75b7d85a424531eb583cf79robbiew
82556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (close(nfd) == -1) {
826d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("close");
827d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
828d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
829d45662739871a315e75b7d85a424531eb583cf79robbiew	}
830d45662739871a315e75b7d85a424531eb583cf79robbiew}
831d45662739871a315e75b7d85a424531eb583cf79robbiew
832d45662739871a315e75b7d85a424531eb583cf79robbiew/*
833d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test21A()    - tests the assertion:
834d45662739871a315e75b7d85a424531eb583cf79robbiew *      On a call to int nftw(const char *path, int (*fn)(const char *, const
835d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall
836d45662739871a315e75b7d85a424531eb583cf79robbiew *      be the maximum number of file descriptors used for the search.
837d45662739871a315e75b7d85a424531eb583cf79robbiew */
838d45662739871a315e75b7d85a424531eb583cf79robbiew
83956207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test21A(void)
840d45662739871a315e75b7d85a424531eb583cf79robbiew{
84156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[] = "./tmp/data/dirh";
84256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val;
843d45662739871a315e75b7d85a424531eb583cf79robbiew
844d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
84556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
84656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: No more than depth file descriptors used in traversal\n");
847d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
848d45662739871a315e75b7d85a424531eb583cf79robbiew
84956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	/*this is the fd we expect if 0 are used */
85056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((next_fd[0] = open(path, O_RDONLY)) == -1) {
851d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("open next_fd[0]");
852d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
853d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
854d45662739871a315e75b7d85a424531eb583cf79robbiew	}
855d45662739871a315e75b7d85a424531eb583cf79robbiew
85656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	/*this is the fd we expect if 1 is used */
85756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((next_fd[1] = open(path, O_RDONLY)) == -1) {
858d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("open next_fd[1]");
859d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
860d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
861d45662739871a315e75b7d85a424531eb583cf79robbiew	}
862d45662739871a315e75b7d85a424531eb583cf79robbiew
86356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (close(next_fd[0]) == -1) {
864d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("close next_fd[0]");
865d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
866d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
867d45662739871a315e75b7d85a424531eb583cf79robbiew	}
868d45662739871a315e75b7d85a424531eb583cf79robbiew
86956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (close(next_fd[1]) == -1) {
870d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("close next_fd[1]");
871d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
872d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
873d45662739871a315e75b7d85a424531eb583cf79robbiew	}
874d45662739871a315e75b7d85a424531eb583cf79robbiew
87556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	visit = 0;
87656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	ret_val = nftw(path, test_func21, 1, 0);
877d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == -1) {
878d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
879d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
880d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
881d45662739871a315e75b7d85a424531eb583cf79robbiew	}
882d45662739871a315e75b7d85a424531eb583cf79robbiew
883d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == 999) {
884d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
885d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
886d45662739871a315e75b7d85a424531eb583cf79robbiew	}
887d45662739871a315e75b7d85a424531eb583cf79robbiew}
888d45662739871a315e75b7d85a424531eb583cf79robbiew
889d45662739871a315e75b7d85a424531eb583cf79robbiew/*
890d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test22A()    - tests the assertion:
891d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
892d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) shall use at
893d45662739871a315e75b7d85a424531eb583cf79robbiew *      most one file descriptor for each directory level.
894d45662739871a315e75b7d85a424531eb583cf79robbiew */
895d45662739871a315e75b7d85a424531eb583cf79robbiew
89656207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test22A(void)
897d45662739871a315e75b7d85a424531eb583cf79robbiew{
89856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	char path[] = "./tmp/data/dirh";
89956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret_val, i;
900d45662739871a315e75b7d85a424531eb583cf79robbiew
901d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < 4; i++) {
90256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		if ((next_fd[i] = open(path, O_RDONLY)) == -1) {
903d45662739871a315e75b7d85a424531eb583cf79robbiew			perror("open");
904d45662739871a315e75b7d85a424531eb583cf79robbiew			cleanup_function();
905d45662739871a315e75b7d85a424531eb583cf79robbiew			fail_exit();
906d45662739871a315e75b7d85a424531eb583cf79robbiew		}
907d45662739871a315e75b7d85a424531eb583cf79robbiew	}
908d45662739871a315e75b7d85a424531eb583cf79robbiew
909d45662739871a315e75b7d85a424531eb583cf79robbiew	for (i = 0; i < 4; i++) {
91056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		if (close(next_fd[i]) == -1) {
911d45662739871a315e75b7d85a424531eb583cf79robbiew			perror("close");
912d45662739871a315e75b7d85a424531eb583cf79robbiew			cleanup_function();
913d45662739871a315e75b7d85a424531eb583cf79robbiew			fail_exit();
914d45662739871a315e75b7d85a424531eb583cf79robbiew		}
915d45662739871a315e75b7d85a424531eb583cf79robbiew	}
916d45662739871a315e75b7d85a424531eb583cf79robbiew
917d45662739871a315e75b7d85a424531eb583cf79robbiew	visit = 0;
918d45662739871a315e75b7d85a424531eb583cf79robbiew
919d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
92056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
92156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: No more than 1 fd per level is used in traversal\n");
922d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
923d45662739871a315e75b7d85a424531eb583cf79robbiew
924d45662739871a315e75b7d85a424531eb583cf79robbiew	ret_val = nftw(path, test_func22, MAX_FD, 0);
925d45662739871a315e75b7d85a424531eb583cf79robbiew
926d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == -1) {
927d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
928d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
929d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
930d45662739871a315e75b7d85a424531eb583cf79robbiew	}
931d45662739871a315e75b7d85a424531eb583cf79robbiew
932d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret_val == 999) {
933d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
934d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
935d45662739871a315e75b7d85a424531eb583cf79robbiew	}
936d45662739871a315e75b7d85a424531eb583cf79robbiew}
937d45662739871a315e75b7d85a424531eb583cf79robbiew
938d45662739871a315e75b7d85a424531eb583cf79robbiew/*
939d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test23A()    - tests the assertion:
940d45662739871a315e75b7d85a424531eb583cf79robbiew *      A call to int nftw(const char *path, int (*fn)(const char *, const
941d45662739871a315e75b7d85a424531eb583cf79robbiew *      struct stat *, int, struct FTW *), int depth, int flags) when the
942d45662739871a315e75b7d85a424531eb583cf79robbiew *      function fn returns a non-zero value shall stop and return the value
943d45662739871a315e75b7d85a424531eb583cf79robbiew *      returned by fn.
944d45662739871a315e75b7d85a424531eb583cf79robbiew */
945d45662739871a315e75b7d85a424531eb583cf79robbiew
94656207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test23A(void)
947d45662739871a315e75b7d85a424531eb583cf79robbiew{
94856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int ret;
949d45662739871a315e75b7d85a424531eb583cf79robbiew
95056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	visit = 0;
951d45662739871a315e75b7d85a424531eb583cf79robbiew
952d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
95356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	fprintf(temp,
95456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		"TEST: The function nftw should return with value set by fn\n");
955d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
956d45662739871a315e75b7d85a424531eb583cf79robbiew
95756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if ((ret =
95856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	     nftw("./tmp/data/dirh", test_func23, MAX_FD, FTW_PHYS)) == -1) {
959d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("nftw");
960d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
961d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
962d45662739871a315e75b7d85a424531eb583cf79robbiew	}
963d45662739871a315e75b7d85a424531eb583cf79robbiew
964d45662739871a315e75b7d85a424531eb583cf79robbiew	if (ret != 999) {
96556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp,
96656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"ERROR: nftw did not return value returned by fn()\n");
967d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
968d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
969d45662739871a315e75b7d85a424531eb583cf79robbiew	}
97056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (visit != 4) {
97156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak		fprintf(temp,
97256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			"ERROR: nftw() did not return immediately on non-zero fn() return\n");
973d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
974d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
975d45662739871a315e75b7d85a424531eb583cf79robbiew	}
976d45662739871a315e75b7d85a424531eb583cf79robbiew}
977d45662739871a315e75b7d85a424531eb583cf79robbiew
978d45662739871a315e75b7d85a424531eb583cf79robbiew/*
979d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test24A()    - tests the assertion:
980d45662739871a315e75b7d85a424531eb583cf79robbiew *      ENAMETOOLONG in errno and return -1 on a call to int nftw(const char
981d45662739871a315e75b7d85a424531eb583cf79robbiew *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
982d45662739871a315e75b7d85a424531eb583cf79robbiew *      *), int depth, int flags) when the length of path exceeds PATH_MAX.
983d45662739871a315e75b7d85a424531eb583cf79robbiew */
984d45662739871a315e75b7d85a424531eb583cf79robbiew
98556207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test24A(void)
986d45662739871a315e75b7d85a424531eb583cf79robbiew{
9874bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENAMETOOLONG_path("nftw", callback, -1);
988d45662739871a315e75b7d85a424531eb583cf79robbiew}
989d45662739871a315e75b7d85a424531eb583cf79robbiew
990d45662739871a315e75b7d85a424531eb583cf79robbiew/*
991d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test25A()    - tests the assertion:
992d45662739871a315e75b7d85a424531eb583cf79robbiew *      ENAMETOOLONG in errno and return -1 on a call to int nftw(const char
993d45662739871a315e75b7d85a424531eb583cf79robbiew *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
994d45662739871a315e75b7d85a424531eb583cf79robbiew *      *), int depth, int flags) when a component of path exceeds NAME_MAX.
995d45662739871a315e75b7d85a424531eb583cf79robbiew */
996d45662739871a315e75b7d85a424531eb583cf79robbiew
99756207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test25A(void)
998d45662739871a315e75b7d85a424531eb583cf79robbiew{
9994bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENAMETOOLONG_name("nftw", callback, -1);
1000d45662739871a315e75b7d85a424531eb583cf79robbiew}
1001d45662739871a315e75b7d85a424531eb583cf79robbiew
1002d45662739871a315e75b7d85a424531eb583cf79robbiew/*
1003d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test26A()    - tests the assertion:
1004d45662739871a315e75b7d85a424531eb583cf79robbiew *      ENOENT in errno and return -1 on a call to int nftw(const char *path,
1005d45662739871a315e75b7d85a424531eb583cf79robbiew *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1006d45662739871a315e75b7d85a424531eb583cf79robbiew *      depth, int flags) when path points to a file which does not exist.
1007d45662739871a315e75b7d85a424531eb583cf79robbiew */
1008d45662739871a315e75b7d85a424531eb583cf79robbiew
100956207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test26A(void)
1010d45662739871a315e75b7d85a424531eb583cf79robbiew{
1011d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
1012d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: [ENOENT] && -1 returned by nftw\n");
1013d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
1014d45662739871a315e75b7d85a424531eb583cf79robbiew
10154bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENOENT_nofile("nftw", callback, -1);
1016d45662739871a315e75b7d85a424531eb583cf79robbiew}
1017d45662739871a315e75b7d85a424531eb583cf79robbiew
1018d45662739871a315e75b7d85a424531eb583cf79robbiew/*
1019d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test27A()    - tests the assertion:
1020d45662739871a315e75b7d85a424531eb583cf79robbiew *      ENOENT in errno and return -1 on a call to int nftw(const char *path,
1021d45662739871a315e75b7d85a424531eb583cf79robbiew *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1022d45662739871a315e75b7d85a424531eb583cf79robbiew *      depth, int flags) when path points to an empty string.
1023d45662739871a315e75b7d85a424531eb583cf79robbiew */
1024d45662739871a315e75b7d85a424531eb583cf79robbiew
102556207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test27A(void)
1026d45662739871a315e75b7d85a424531eb583cf79robbiew{
1027d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
1028d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: The function nftw should return with a -1\n");
1029d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
1030d45662739871a315e75b7d85a424531eb583cf79robbiew
10314bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENOENT_empty("nftw", callback, -1);
1032d45662739871a315e75b7d85a424531eb583cf79robbiew}
1033d45662739871a315e75b7d85a424531eb583cf79robbiew
1034d45662739871a315e75b7d85a424531eb583cf79robbiew/*
1035d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test28A()    - tests the assertion:
1036d45662739871a315e75b7d85a424531eb583cf79robbiew *      ENOTDIR in errno and return -1 on a call to int nftw(const char
1037d45662739871a315e75b7d85a424531eb583cf79robbiew *      *path, int (*fn)(const char *, const struct stat *, int, struct FTW
1038d45662739871a315e75b7d85a424531eb583cf79robbiew *      *), int depth, int flags) when path is not a directory.
1039d45662739871a315e75b7d85a424531eb583cf79robbiew */
1040d45662739871a315e75b7d85a424531eb583cf79robbiew
104156207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test28A(void)
1042d45662739871a315e75b7d85a424531eb583cf79robbiew{
1043d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
1044d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: [ENOTDIR] && -1 returned by nftw\n");
1045d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
1046d45662739871a315e75b7d85a424531eb583cf79robbiew
10474bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENOTDIR("nftw", callback, -1);
1048d45662739871a315e75b7d85a424531eb583cf79robbiew}
1049d45662739871a315e75b7d85a424531eb583cf79robbiew
1050d45662739871a315e75b7d85a424531eb583cf79robbiew/*
1051d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test29A()    - tests the assertion:
1052d45662739871a315e75b7d85a424531eb583cf79robbiew *      EACCES in errno and return -1 on a call to int nftw(const char *path,
1053d45662739871a315e75b7d85a424531eb583cf79robbiew *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1054d45662739871a315e75b7d85a424531eb583cf79robbiew *      depth, int flags) when search permission is denied for any component
1055d45662739871a315e75b7d85a424531eb583cf79robbiew *      of path.
1056d45662739871a315e75b7d85a424531eb583cf79robbiew */
1057d45662739871a315e75b7d85a424531eb583cf79robbiew
105856207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test29A(void)
1059d45662739871a315e75b7d85a424531eb583cf79robbiew{
106056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (chmod("./tmp/data/d333", (mode_t) S_IRUSR) == -1) {
1061d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("chmod");
1062d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
1063d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
1064d45662739871a315e75b7d85a424531eb583cf79robbiew	}
1065d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
1066d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: [EACCES] && -1 returned by nftw\n");
1067d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
1068d45662739871a315e75b7d85a424531eb583cf79robbiew
10694bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENOTDIR("nftw", callback, -1);
1070d45662739871a315e75b7d85a424531eb583cf79robbiew}
1071d45662739871a315e75b7d85a424531eb583cf79robbiew
1072d45662739871a315e75b7d85a424531eb583cf79robbiew/*
1073d45662739871a315e75b7d85a424531eb583cf79robbiew *    void test30A()    - tests the assertion:
1074d45662739871a315e75b7d85a424531eb583cf79robbiew *      EACCES in errno and return -1 on a call to int nftw(const char *path,
1075d45662739871a315e75b7d85a424531eb583cf79robbiew *      int (*fn)(const char *, const struct stat *, int, struct FTW *), int
1076d45662739871a315e75b7d85a424531eb583cf79robbiew *      depth, int flags) when read permission is denied for path.
1077d45662739871a315e75b7d85a424531eb583cf79robbiew */
1078d45662739871a315e75b7d85a424531eb583cf79robbiew
107956207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid test30A(void)
1080d45662739871a315e75b7d85a424531eb583cf79robbiew{
108156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	if (chmod("./tmp/data/d333", (mode_t) S_IXUSR) == -1) {
1082d45662739871a315e75b7d85a424531eb583cf79robbiew		perror("chmod");
1083d45662739871a315e75b7d85a424531eb583cf79robbiew		cleanup_function();
1084d45662739871a315e75b7d85a424531eb583cf79robbiew		fail_exit();
1085d45662739871a315e75b7d85a424531eb583cf79robbiew	}
1086d45662739871a315e75b7d85a424531eb583cf79robbiew#ifdef DEBUG
1087d45662739871a315e75b7d85a424531eb583cf79robbiew	fprintf(temp, "TEST: [EACCES] && -1 returned by nftw\n");
1088d45662739871a315e75b7d85a424531eb583cf79robbiew#endif
10894bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak	test_ENOTDIR("nftw", callback, -1);
1090ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
1091