reindent-20030715
[openafs.git] / src / util / test / treaddir.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * test readdir routines.
12 * Need to ensure that opendir succeeds if the directory is empty. To that
13  * end report the NT error for any failure.
14  * Basic tests to do:
15  * 1) Read non-existent directory.
16  * 2) Read empty <drive:>
17  * 3) Try to read a file.
18  */
19 #include <afsconfig.h>
20 #include <afs/param.h>
21
22 RCSID
23     ("$Header$");
24
25 #include <stdio.h>
26 #include <errno.h>
27 #include <dirent.h>
28
29 main(int ac, char **av)
30 {
31     int i;
32     DIR *dirp;
33     struct dirent *direntp;
34     int first;
35
36
37     if (ac < 2) {
38         printf("Usage: treaddir dir [dir ....]\n");
39         return -1;
40     }
41
42     for (i = 1; i < ac; i++) {
43         dirp = opendir(av[i]);
44         if (!dirp) {
45 #ifdef AFS_NT40_ENV
46             printf("Can't open directory \"%s\", errno=%d, NT error=%d\n",
47                    av[i], errno, GetLastError());
48 #else
49             printf("Can't open directory \"%s\", errno=%d\n", av[i], errno);
50 #endif
51             continue;
52         }
53
54         first = 1;
55         errno = 0;
56         while (direntp = readdir(dirp)) {
57             if (first) {
58                 first = 0;
59                 if (i > 1)
60                     printf("\n");
61             }
62             printf("%s\n", direntp->d_name);
63         }
64 #ifdef AFS_NT40_ENV
65         if (errno) {
66             printf
67                 ("readdir failed in directory %s with errno=%d, NT error=%d\n",
68                  av[i], errno, GetLastError());
69         }
70 #endif
71         (void)closedir(dirp);
72     }
73
74     return 0;
75 }