]> git.sur5r.net Git - cc65/blob - testcode/lib/dir-test.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / testcode / lib / dir-test.c
1
2 /*
3         first test for posix directory routines for the c64
4         kludges:
5         -   currently uses cbm_open, which conflicts with standard i/o,
6                 which in turn makes it infact kindof unuseable. this can
7                 be easily changed however, since the only reason not to use
8                 open/read was that it currently appends ,u,r to filenames
9         -   the offset in current dir stream should better be calculated
10                 from the values returned by "read".
11         -   the type flag isnt filled in atm.
12         -   scandir/alphasort/versionsort is missing
13         -   some bits are currently untested (ie, unused in the testprogram)
14         27/02/2003 gpz
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <errno.h>
21 #include <dirent.h>
22 #include <cbm.h>
23 #include <conio.h>
24
25
26 int main(void)
27 {
28     char* name = ".";
29     unsigned char go = 0;
30     DIR *D;
31     register struct dirent* E;
32
33     /* Explain usage and wait for a key */
34     printf ("Use the following keys:\n"
35             "  g -> go ahead without stop\n"
36             "  q -> quit directory listing\n"
37             "  r -> return to last entry\n"
38             "  s -> seek back to start\n"
39             "Press any key to start ...\n");
40     cgetc ();
41
42     /* Open the directory */
43     D = opendir (name);
44     if (D == 0) {
45         printf("error opening %s: %s\n", name, strerror (errno));
46         return 1;
47     }
48
49     /* Output the directory */
50     errno = 0;
51     printf("contents of \"%s\":\n", name);
52     while ((E = readdir (D)) != 0) {
53         printf ("dirent.d_name[] : \"%s\"\n", E->d_name);
54         printf ("dirent.d_blocks : %10u\n",   E->d_blocks);
55         printf ("dirent.d_type   : %10d\n",   E->d_type);
56         printf ("telldir()       : %10lu\n",  telldir (D));
57         printf ("---\n");
58         if (!go) {
59             switch (cgetc ()) {
60                 case 'g':
61                     go = 1;
62                     break;
63
64                 case 'q':
65                     goto done;
66
67                 case 'r':
68                     seekdir (D, E->d_off);
69                     break;
70
71                 case 's':
72                     rewinddir (D);
73                     break;
74
75             }
76         }
77     }
78
79 done:
80     if (errno == 0) {
81         printf ("Done\n");
82     } else {
83         printf("Done: %d (%s)\n", errno, strerror (errno));
84     }
85
86     /* Close the directory */
87     closedir (D);
88
89     return 0;
90 }