1*433d6423SLionel Sambuc /* Test24: opendir, readdir, rewinddir, closedir Author: Jan-Mark Wams */
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc #include <sys/types.h>
4*433d6423SLionel Sambuc #include <sys/stat.h>
5*433d6423SLionel Sambuc #include <sys/wait.h>
6*433d6423SLionel Sambuc #include <string.h>
7*433d6423SLionel Sambuc #include <stdlib.h>
8*433d6423SLionel Sambuc #include <unistd.h>
9*433d6423SLionel Sambuc #include <limits.h>
10*433d6423SLionel Sambuc #include <fcntl.h>
11*433d6423SLionel Sambuc #include <dirent.h>
12*433d6423SLionel Sambuc #include <errno.h>
13*433d6423SLionel Sambuc #include <time.h>
14*433d6423SLionel Sambuc #include <stdio.h>
15*433d6423SLionel Sambuc
16*433d6423SLionel Sambuc void chk_dir(DIR * dirpntr);
17*433d6423SLionel Sambuc void test24a(void);
18*433d6423SLionel Sambuc void test24b(void);
19*433d6423SLionel Sambuc void test24c(void);
20*433d6423SLionel Sambuc void makelongnames(void);
21*433d6423SLionel Sambuc
22*433d6423SLionel Sambuc #define OVERFLOW_DIR_NR (OPEN_MAX + 1)
23*433d6423SLionel Sambuc int max_error = 4;
24*433d6423SLionel Sambuc #include "common.h"
25*433d6423SLionel Sambuc
26*433d6423SLionel Sambuc #define ITERATIONS 5
27*433d6423SLionel Sambuc
28*433d6423SLionel Sambuc
29*433d6423SLionel Sambuc #define DIRENT0 ((struct dirent *) NULL)
30*433d6423SLionel Sambuc #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd)
31*433d6423SLionel Sambuc #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir)
32*433d6423SLionel Sambuc
33*433d6423SLionel Sambuc int subtest = 1;
34*433d6423SLionel Sambuc int superuser;
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc char *MaxName; /* Name of maximum length */
37*433d6423SLionel Sambuc char MaxPath[PATH_MAX]; /* Same for path */
38*433d6423SLionel Sambuc char *ToLongName; /* Name of maximum +1 length */
39*433d6423SLionel Sambuc char ToLongPath[PATH_MAX + 1]; /* Same for path, both too long */
40*433d6423SLionel Sambuc
main(int argc,char * argv[])41*433d6423SLionel Sambuc int main(int argc, char *argv[])
42*433d6423SLionel Sambuc {
43*433d6423SLionel Sambuc int i, m = 0xFFFF;
44*433d6423SLionel Sambuc
45*433d6423SLionel Sambuc start(24);
46*433d6423SLionel Sambuc if (argc == 2) m = atoi(argv[1]);
47*433d6423SLionel Sambuc makelongnames();
48*433d6423SLionel Sambuc superuser = (geteuid() == 0);
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc for (i = 0; i < ITERATIONS; i++) {
51*433d6423SLionel Sambuc if (m & 0001) test24a();
52*433d6423SLionel Sambuc if (m & 0002) test24b();
53*433d6423SLionel Sambuc if (m & 0004) test24c();
54*433d6423SLionel Sambuc }
55*433d6423SLionel Sambuc quit();
56*433d6423SLionel Sambuc
57*433d6423SLionel Sambuc return(-1); /* Unreachable */
58*433d6423SLionel Sambuc }
59*433d6423SLionel Sambuc
test24a()60*433d6423SLionel Sambuc void test24a()
61*433d6423SLionel Sambuc { /* Test normal operations. */
62*433d6423SLionel Sambuc int fd3, fd4, fd5;
63*433d6423SLionel Sambuc DIR *dirp;
64*433d6423SLionel Sambuc int j, ret, fd, flags;
65*433d6423SLionel Sambuc struct stat st1, st2;
66*433d6423SLionel Sambuc int stat_loc;
67*433d6423SLionel Sambuc time_t time1;
68*433d6423SLionel Sambuc
69*433d6423SLionel Sambuc subtest = 1;
70*433d6423SLionel Sambuc
71*433d6423SLionel Sambuc System("rm -rf ../DIR_24/*");
72*433d6423SLionel Sambuc
73*433d6423SLionel Sambuc if ((fd = dup(0)) != 3) e(1); /* dup stdin */
74*433d6423SLionel Sambuc close(fd); /* free the fd again */
75*433d6423SLionel Sambuc errno= 0;
76*433d6423SLionel Sambuc dirp = opendir("/"); /* open "/" */
77*433d6423SLionel Sambuc if (dirp == ((DIR *) NULL)) e(2); /* has to succseed */
78*433d6423SLionel Sambuc if (errno != 0) e(3); /* success implies errno didn't change */
79*433d6423SLionel Sambuc if ((fd = dup(0)) <= 2) e(4); /* dup stdin */
80*433d6423SLionel Sambuc if (fd > 3) { /* if opendir() uses fd 3 */
81*433d6423SLionel Sambuc flags = fcntl(3, F_GETFD); /* get fd fags of 3 */
82*433d6423SLionel Sambuc if (!(flags & FD_CLOEXEC)) e(5); /* it should be closed on */
83*433d6423SLionel Sambuc } /* exec..() calls */
84*433d6423SLionel Sambuc close(fd); /* free the fd again */
85*433d6423SLionel Sambuc ret = closedir(dirp); /* close, we don't need it */
86*433d6423SLionel Sambuc if (ret == -1) e(6); /* closedir () unsucces full */
87*433d6423SLionel Sambuc if (ret != 0) e(7); /* should be 0 or -1 */
88*433d6423SLionel Sambuc if ((fd = dup(0)) != 3) e(8); /* see if next fd is same */
89*433d6423SLionel Sambuc close(fd); /* free the fd again */
90*433d6423SLionel Sambuc
91*433d6423SLionel Sambuc System("rm -rf foo; mkdir foo");
92*433d6423SLionel Sambuc Chdir("foo");
93*433d6423SLionel Sambuc System("touch f1 f2 f3 f4 f5"); /* make f1 .. f5 */
94*433d6423SLionel Sambuc System("rm f[24]"); /* creat `holes' in entrys */
95*433d6423SLionel Sambuc Chdir("..");
96*433d6423SLionel Sambuc
97*433d6423SLionel Sambuc if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(9); /* open foo */
98*433d6423SLionel Sambuc chk_dir(dirp); /* test if foo's ok */
99*433d6423SLionel Sambuc for (j = 0; j < 10; j++) {
100*433d6423SLionel Sambuc errno = j * 47 % 7; /* there should */
101*433d6423SLionel Sambuc if (readdir(dirp) != DIRENT0) e(10); /* be nomore dir */
102*433d6423SLionel Sambuc if (errno != j * 47 % 7) e(11); /* entrys */
103*433d6423SLionel Sambuc }
104*433d6423SLionel Sambuc rewinddir(dirp); /* rewind foo */
105*433d6423SLionel Sambuc chk_dir(dirp); /* test foosok */
106*433d6423SLionel Sambuc for (j = 0; j < 10; j++) {
107*433d6423SLionel Sambuc errno = j * 23 % 7; /* there should */
108*433d6423SLionel Sambuc if (readdir(dirp) != DIRENT0) e(12); /* be nomore dir */
109*433d6423SLionel Sambuc if (errno != j * 23 % 7) e(13); /* entrys */
110*433d6423SLionel Sambuc }
111*433d6423SLionel Sambuc if ((fd4 = creat("foo/f4", 0666)) <= 2) e(14); /* Open a file. */
112*433d6423SLionel Sambuc System("rm foo/f4"); /* Kill entry. */
113*433d6423SLionel Sambuc rewinddir(dirp); /* Rewind foo. */
114*433d6423SLionel Sambuc if ((fd3 = open("foo/f3", O_WRONLY)) <= 2) e(15); /* Open more files. */
115*433d6423SLionel Sambuc if ((fd5 = open("foo/f5", O_WRONLY)) <= 2) e(16);
116*433d6423SLionel Sambuc if (write(fd3, "Hello", 6) != 6) e(17);
117*433d6423SLionel Sambuc if (write(fd4, "Hello", 6) != 6) e(18); /* write some data */
118*433d6423SLionel Sambuc if (close(fd5) != 0) e(19);
119*433d6423SLionel Sambuc chk_dir(dirp);
120*433d6423SLionel Sambuc for (j = 0; j < 10; j++) {
121*433d6423SLionel Sambuc errno = j * 101 % 7; /* there should */
122*433d6423SLionel Sambuc if (readdir(dirp) != DIRENT0) e(20); /* be nomore dir */
123*433d6423SLionel Sambuc if (errno != j * 101 % 7) e(21); /* entrys */
124*433d6423SLionel Sambuc }
125*433d6423SLionel Sambuc if (close(fd4) != 0) e(22); /* shouldn't matter */
126*433d6423SLionel Sambuc if (close(fd3) != 0) e(23); /* when we do this */
127*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(24); /* close foo again */
128*433d6423SLionel Sambuc
129*433d6423SLionel Sambuc Chdir("foo");
130*433d6423SLionel Sambuc if ((dirp = opendir(".//")) == ((DIR *) NULL)) e(25); /* open foo again */
131*433d6423SLionel Sambuc Chdir("..");
132*433d6423SLionel Sambuc chk_dir(dirp); /* foosok? */
133*433d6423SLionel Sambuc for (j = 0; j < 10; j++) {
134*433d6423SLionel Sambuc errno = (j * 101) % 7; /* there should */
135*433d6423SLionel Sambuc if (readdir(dirp) != DIRENT0) e(26); /* be nomore dir */
136*433d6423SLionel Sambuc if (errno != (j * 101) % 7) e(27); /* entrys */
137*433d6423SLionel Sambuc }
138*433d6423SLionel Sambuc
139*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(28); /* It should be closable */
140*433d6423SLionel Sambuc
141*433d6423SLionel Sambuc stat("foo", &st1); /* get stat */
142*433d6423SLionel Sambuc time(&time1);
143*433d6423SLionel Sambuc while (time1 >= time((time_t *)0))
144*433d6423SLionel Sambuc ;
145*433d6423SLionel Sambuc if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(29); /* open, */
146*433d6423SLionel Sambuc if (readdir(dirp) == DIRENT0) e(30); /* read and */
147*433d6423SLionel Sambuc stat("foo", &st2); /* get new stat */
148*433d6423SLionel Sambuc if (st1.st_atime > st2.st_atime) e(31); /* st_atime check */
149*433d6423SLionel Sambuc
150*433d6423SLionel Sambuc switch (fork()) {
151*433d6423SLionel Sambuc case -1: printf("Can't fork\n"); break;
152*433d6423SLionel Sambuc case 0:
153*433d6423SLionel Sambuc rewinddir(dirp); /* rewind childs dirp */
154*433d6423SLionel Sambuc if (readdir(dirp) == DIRENT0) e(32); /* read should be ok */
155*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(33); /* close child'd foo */
156*433d6423SLionel Sambuc exit(0); /* 0 stops here */
157*433d6423SLionel Sambuc default:
158*433d6423SLionel Sambuc if (wait(&stat_loc) == -1) e(34); /* PARENT wait()'s */
159*433d6423SLionel Sambuc break;
160*433d6423SLionel Sambuc }
161*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(35); /* close parent's foo */
162*433d6423SLionel Sambuc }
163*433d6423SLionel Sambuc
test24b()164*433d6423SLionel Sambuc void test24b()
165*433d6423SLionel Sambuc {
166*433d6423SLionel Sambuc /* See what happens with too many dir's open. Check if file size seems ok,
167*433d6423SLionel Sambuc * and independency.
168*433d6423SLionel Sambuc */
169*433d6423SLionel Sambuc
170*433d6423SLionel Sambuc int i, j; /* i = highest open dir count */
171*433d6423SLionel Sambuc DIR *dirp[OVERFLOW_DIR_NR], *dp;
172*433d6423SLionel Sambuc struct dirent *dep, *dep1, *dep2;
173*433d6423SLionel Sambuc char *name; /* buffer for file name, and count */
174*433d6423SLionel Sambuc int dot = 0, dotdot = 0;
175*433d6423SLionel Sambuc int max_name_length;
176*433d6423SLionel Sambuc
177*433d6423SLionel Sambuc subtest = 2;
178*433d6423SLionel Sambuc
179*433d6423SLionel Sambuc System("rm -rf ../DIR_24/*");
180*433d6423SLionel Sambuc
181*433d6423SLionel Sambuc max_name_length = name_max(".");
182*433d6423SLionel Sambuc name = malloc(max_name_length + 2);
183*433d6423SLionel Sambuc memset(name, '\0', max_name_length + 2);
184*433d6423SLionel Sambuc
185*433d6423SLionel Sambuc for (i = 0; i < OVERFLOW_DIR_NR; i++) {
186*433d6423SLionel Sambuc dirp[i] = opendir("/");
187*433d6423SLionel Sambuc if (dirp[i] == ((DIR *) NULL)) {
188*433d6423SLionel Sambuc if (errno != EMFILE) e(1);
189*433d6423SLionel Sambuc break;
190*433d6423SLionel Sambuc }
191*433d6423SLionel Sambuc }
192*433d6423SLionel Sambuc if (i <= 4) e(2); /* sounds resanable */
193*433d6423SLionel Sambuc if (i >= OVERFLOW_DIR_NR) e(3); /* might be to small */
194*433d6423SLionel Sambuc for (j = 0; j < i; j++) {
195*433d6423SLionel Sambuc if (closedir(dirp[(j + 5) % i]) != 0) e(4); /* neat! */
196*433d6423SLionel Sambuc }
197*433d6423SLionel Sambuc
198*433d6423SLionel Sambuc /* Now check if number of bytes in d_name can go up till NAME_MAX */
199*433d6423SLionel Sambuc System("rm -rf foo; mkdir foo");
200*433d6423SLionel Sambuc Chdir("foo");
201*433d6423SLionel Sambuc name[0] = 0;
202*433d6423SLionel Sambuc for (i = 0; i <= max_name_length; i++) {
203*433d6423SLionel Sambuc if (strcat(name, "X") != name) e(5);
204*433d6423SLionel Sambuc close(creat(name, 0666)); /* fails once on */
205*433d6423SLionel Sambuc } /* XX..XX, 1 too long */
206*433d6423SLionel Sambuc Chdir("..");
207*433d6423SLionel Sambuc /* Now change i-th X to Y in name buffer record file of length i. */
208*433d6423SLionel Sambuc if ((dp = opendir("foo")) == ((DIR *) NULL)) e(6);
209*433d6423SLionel Sambuc while ((dep = readdir(dp)) != DIRENT0) {
210*433d6423SLionel Sambuc if (strcmp("..", dep->d_name) == 0)
211*433d6423SLionel Sambuc dotdot++;
212*433d6423SLionel Sambuc else if (strcmp(".", dep->d_name) == 0)
213*433d6423SLionel Sambuc dot++;
214*433d6423SLionel Sambuc else
215*433d6423SLionel Sambuc name[strlen(dep->d_name)] += 1; /* 'X' + 1 == 'Y' */
216*433d6423SLionel Sambuc }
217*433d6423SLionel Sambuc if (closedir(dp) != 0) e(7);
218*433d6423SLionel Sambuc for (i = 1; i <= max_name_length; i++) { /* Check if every length */
219*433d6423SLionel Sambuc if (name[i] != 'Y') e(8); /* has been seen once. */
220*433d6423SLionel Sambuc }
221*433d6423SLionel Sambuc
222*433d6423SLionel Sambuc /* Check upper and lower bound. */
223*433d6423SLionel Sambuc if (name[0] != 'X') e(9);
224*433d6423SLionel Sambuc if (name[max_name_length + 1] != '\0') e(10);
225*433d6423SLionel Sambuc
226*433d6423SLionel Sambuc /* Now check if two simultaniouse open dirs do the same */
227*433d6423SLionel Sambuc if ((dirp[1] = opendir("foo")) == ((DIR *) NULL)) e(11);
228*433d6423SLionel Sambuc if ((dirp[2] = opendir("foo")) == ((DIR *) NULL)) e(12);
229*433d6423SLionel Sambuc if ((dep1 = readdir(dirp[1])) == DIRENT0) e(13);
230*433d6423SLionel Sambuc if ((dep2 = readdir(dirp[2])) == DIRENT0) e(14);
231*433d6423SLionel Sambuc if (dep1->d_name == dep2->d_name) e(15); /* 1 & 2 Should be */
232*433d6423SLionel Sambuc strcpy(name, dep2->d_name); /* differand buffers */
233*433d6423SLionel Sambuc if (strcmp(dep1->d_name, name) != 0) e(16); /* But hold the same */
234*433d6423SLionel Sambuc if ((dep1 = readdir(dirp[1])) == DIRENT0) e(17);
235*433d6423SLionel Sambuc if ((dep1 = readdir(dirp[1])) == DIRENT0) e(18); /* lose some entries */
236*433d6423SLionel Sambuc if ((dep1 = readdir(dirp[1])) == DIRENT0) e(19); /* Using dirp 1 has */
237*433d6423SLionel Sambuc if (dep1->d_name == dep2->d_name) e(20); /* no effect on 2 */
238*433d6423SLionel Sambuc if (strcmp(dep2->d_name, name) != 0) e(21);
239*433d6423SLionel Sambuc rewinddir(dirp[1]); /* Rewinding dirp 1 */
240*433d6423SLionel Sambuc if ((dep2 = readdir(dirp[2])) == DIRENT0) e(22); /* can't effect 2 */
241*433d6423SLionel Sambuc if (strcmp(dep2->d_name, name) == 0) e(23); /* Must be next */
242*433d6423SLionel Sambuc if (closedir(dirp[1]) != 0) e(24); /* Closing dirp 1 */
243*433d6423SLionel Sambuc if ((dep2 = readdir(dirp[2])) == DIRENT0) e(25); /* can't effect 2 */
244*433d6423SLionel Sambuc if (strcmp(dep2->d_name, name) == 0) e(26); /* Must be next */
245*433d6423SLionel Sambuc if (closedir(dirp[2]) != 0) e(27);
246*433d6423SLionel Sambuc free(name);
247*433d6423SLionel Sambuc }
248*433d6423SLionel Sambuc
test24c()249*433d6423SLionel Sambuc void test24c()
250*433d6423SLionel Sambuc {
251*433d6423SLionel Sambuc /* Test whether wrong things go wrong right. */
252*433d6423SLionel Sambuc
253*433d6423SLionel Sambuc DIR *dirp;
254*433d6423SLionel Sambuc int does_truncate;
255*433d6423SLionel Sambuc
256*433d6423SLionel Sambuc subtest = 3;
257*433d6423SLionel Sambuc
258*433d6423SLionel Sambuc System("rm -rf ../DIR_24/*");
259*433d6423SLionel Sambuc
260*433d6423SLionel Sambuc if (opendir("foo/bar/nono") != ((DIR *) NULL)) e(1); /* nonexistent */
261*433d6423SLionel Sambuc if (errno != ENOENT) e(2);
262*433d6423SLionel Sambuc System("mkdir foo; chmod 677 foo"); /* foo inaccesable */
263*433d6423SLionel Sambuc if (opendir("foo/bar/nono") != ((DIR *) NULL)) e(3);
264*433d6423SLionel Sambuc if (superuser) {
265*433d6423SLionel Sambuc if (errno != ENOENT) e(4); /* su has access */
266*433d6423SLionel Sambuc System("chmod 377 foo");
267*433d6423SLionel Sambuc if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(5);
268*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(6);
269*433d6423SLionel Sambuc }
270*433d6423SLionel Sambuc if (!superuser) {
271*433d6423SLionel Sambuc if (errno != EACCES) e(7); /* we don't ;-) */
272*433d6423SLionel Sambuc System("chmod 377 foo");
273*433d6423SLionel Sambuc if (opendir("foo") != ((DIR *) NULL)) e(8);
274*433d6423SLionel Sambuc }
275*433d6423SLionel Sambuc System("chmod 777 foo");
276*433d6423SLionel Sambuc
277*433d6423SLionel Sambuc if (mkdir(MaxName, 0777) != 0) e(9); /* make longdir */
278*433d6423SLionel Sambuc if ((dirp = opendir(MaxName)) == ((DIR *) NULL)) e(10); /* open it */
279*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(11); /* close it */
280*433d6423SLionel Sambuc if (rmdir(MaxName) != 0) e(12); /* then remove it */
281*433d6423SLionel Sambuc if ((dirp = opendir(MaxPath)) == ((DIR *) NULL)) e(13); /* open '.' */
282*433d6423SLionel Sambuc if (closedir(dirp) != 0) e(14); /* close it */
283*433d6423SLionel Sambuc
284*433d6423SLionel Sambuc does_truncate = does_fs_truncate();
285*433d6423SLionel Sambuc if (opendir(ToLongName) != ((DIR *) NULL)) e(17); /* is too long */
286*433d6423SLionel Sambuc if (does_truncate) {
287*433d6423SLionel Sambuc if (errno != ENOENT) e(18);
288*433d6423SLionel Sambuc } else {
289*433d6423SLionel Sambuc if (errno != ENAMETOOLONG) e(19);
290*433d6423SLionel Sambuc }
291*433d6423SLionel Sambuc
292*433d6423SLionel Sambuc if (opendir(ToLongPath) != ((DIR *) NULL)) e(20); /* path is too long */
293*433d6423SLionel Sambuc if (errno != ENAMETOOLONG) e(21);
294*433d6423SLionel Sambuc System("touch foo/abc"); /* make a file */
295*433d6423SLionel Sambuc if (opendir("foo/abc") != ((DIR *) NULL)) e(22); /* not a dir */
296*433d6423SLionel Sambuc if (errno != ENOTDIR) e(23);
297*433d6423SLionel Sambuc }
298*433d6423SLionel Sambuc
chk_dir(dirp)299*433d6423SLionel Sambuc void chk_dir(dirp) /* dir should contain */
300*433d6423SLionel Sambuc DIR *dirp; /* (`f1', `f3', `f5', `.', `..') */
301*433d6423SLionel Sambuc { /* no more, no less */
302*433d6423SLionel Sambuc int f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 0, /* counters for all */
303*433d6423SLionel Sambuc other = 0, dot = 0, dotdot = 0; /* possible entrys */
304*433d6423SLionel Sambuc int i;
305*433d6423SLionel Sambuc struct dirent *dep;
306*433d6423SLionel Sambuc char *fname;
307*433d6423SLionel Sambuc int oldsubtest = subtest;
308*433d6423SLionel Sambuc
309*433d6423SLionel Sambuc subtest = 4;
310*433d6423SLionel Sambuc
311*433d6423SLionel Sambuc for (i = 0; i < 5; i++) { /* 3 files and `.' and `..' == 5 entrys */
312*433d6423SLionel Sambuc dep = readdir(dirp);
313*433d6423SLionel Sambuc if (dep == DIRENT0) { /* not einough */
314*433d6423SLionel Sambuc if (dep == DIRENT0) e(1);
315*433d6423SLionel Sambuc break;
316*433d6423SLionel Sambuc }
317*433d6423SLionel Sambuc fname = dep->d_name;
318*433d6423SLionel Sambuc if (strcmp(fname, ".") == 0)
319*433d6423SLionel Sambuc dot++;
320*433d6423SLionel Sambuc else if (strcmp(fname, "..") == 0)
321*433d6423SLionel Sambuc dotdot++;
322*433d6423SLionel Sambuc else if (strcmp(fname, "f1") == 0)
323*433d6423SLionel Sambuc f1++;
324*433d6423SLionel Sambuc else if (strcmp(fname, "f2") == 0)
325*433d6423SLionel Sambuc f2++;
326*433d6423SLionel Sambuc else if (strcmp(fname, "f3") == 0)
327*433d6423SLionel Sambuc f3++;
328*433d6423SLionel Sambuc else if (strcmp(fname, "f4") == 0)
329*433d6423SLionel Sambuc f4++;
330*433d6423SLionel Sambuc else if (strcmp(fname, "f5") == 0)
331*433d6423SLionel Sambuc f5++;
332*433d6423SLionel Sambuc else
333*433d6423SLionel Sambuc other++;
334*433d6423SLionel Sambuc } /* do next dir entry */
335*433d6423SLionel Sambuc
336*433d6423SLionel Sambuc if (dot != 1) e(2); /* Check the entrys */
337*433d6423SLionel Sambuc if (dotdot != 1) e(3);
338*433d6423SLionel Sambuc if (f1 != 1) e(4);
339*433d6423SLionel Sambuc if (f3 != 1) e(5);
340*433d6423SLionel Sambuc if (f5 != 1) e(6);
341*433d6423SLionel Sambuc if (f2 != 0) e(7);
342*433d6423SLionel Sambuc if (f4 != 0) e(8);
343*433d6423SLionel Sambuc if (other != 0) e(9);
344*433d6423SLionel Sambuc
345*433d6423SLionel Sambuc subtest = oldsubtest;
346*433d6423SLionel Sambuc }
347*433d6423SLionel Sambuc
makelongnames()348*433d6423SLionel Sambuc void makelongnames()
349*433d6423SLionel Sambuc {
350*433d6423SLionel Sambuc register int i;
351*433d6423SLionel Sambuc int max_name_length;
352*433d6423SLionel Sambuc
353*433d6423SLionel Sambuc max_name_length = name_max("."); /* Aka NAME_MAX, but not every FS supports
354*433d6423SLionel Sambuc * the same length, hence runtime check */
355*433d6423SLionel Sambuc MaxName = malloc(max_name_length + 1);
356*433d6423SLionel Sambuc ToLongName = malloc(max_name_length + 1 + 1); /* Name of maximum +1 length */
357*433d6423SLionel Sambuc memset(MaxName, 'a', max_name_length);
358*433d6423SLionel Sambuc MaxName[max_name_length] = '\0';
359*433d6423SLionel Sambuc
360*433d6423SLionel Sambuc for (i = 0; i < PATH_MAX - 1; i++) { /* idem path */
361*433d6423SLionel Sambuc MaxPath[i++] = '.';
362*433d6423SLionel Sambuc MaxPath[i] = '/';
363*433d6423SLionel Sambuc }
364*433d6423SLionel Sambuc MaxPath[PATH_MAX - 1] = '\0';
365*433d6423SLionel Sambuc
366*433d6423SLionel Sambuc strcpy(ToLongName, MaxName); /* copy them Max to ToLong */
367*433d6423SLionel Sambuc strcpy(ToLongPath, MaxPath);
368*433d6423SLionel Sambuc
369*433d6423SLionel Sambuc ToLongName[max_name_length] = 'a';
370*433d6423SLionel Sambuc ToLongName[max_name_length+1] = '\0';/* extend ToLongName by one too many */
371*433d6423SLionel Sambuc ToLongPath[PATH_MAX - 1] = '/';
372*433d6423SLionel Sambuc ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */
373*433d6423SLionel Sambuc }
374