include-afsconfig-before-param-h-20010712
[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("$Header$");
23
24 #include <stdio.h>
25 #include <errno.h>
26 #include <dirent.h>
27
28 main(int ac, char **av)
29 {
30     int i;
31     DIR *dirp;
32     struct dirent *direntp;
33     int first;
34
35
36     if (ac < 2) {
37         printf("Usage: treaddir dir [dir ....]\n");
38         return -1;
39     }
40
41     for (i=1; i<ac; i++) {
42         dirp = opendir(av[i]);
43         if (!dirp) {
44 #ifdef AFS_NT40_ENV
45             printf("Can't open directory \"%s\", errno=%d, NT error=%d\n",
46                    av[i], errno, GetLastError());
47 #else
48             printf("Can't open directory \"%s\", errno=%d\n", av[i], errno);
49 #endif
50             continue;
51         }
52
53         first = 1;
54         errno = 0;
55         while (direntp = readdir(dirp)) {
56             if (first) {
57                 first = 0;
58                 if (i > 1) printf("\n");
59             }
60             printf("%s\n", direntp->d_name);
61         }
62 #ifdef AFS_NT40_ENV
63         if (errno) {
64             printf("readdir failed in directory %s with errno=%d, NT error=%d\n",
65                    av[i], errno, GetLastError());
66         }
67 #endif
68         (void) closedir(dirp);
69     }
70
71     return 0;
72 }