2 * Enumerate devices, directories and files.
4 * 2012-10-15, Oliver Schmidt (ol.sc@web.de)
19 void printdir (char *newdir)
21 char olddir[FILENAME_MAX];
22 char curdir[FILENAME_MAX];
29 getcwd (olddir, sizeof (olddir));
32 /* If chdir() fails we just print the
33 * directory name - as done for files.
35 printf (" Dir %s\n", newdir);
39 /* We call getcwd() in order to print the
40 * absolute pathname for a subdirectory.
42 getcwd (curdir, sizeof (curdir));
43 printf (" Dir %s:\n", curdir);
45 /* Calling opendir() always with "." avoids
46 * fiddling around with pathname separators.
49 while (ent = readdir (dir)) {
51 if (_DE_ISREG (ent->d_type)) {
52 printf (" File %s\n", ent->d_name);
56 /* We defer handling of subdirectories until we're done with the
57 * current one as several targets don't support other disk i/o
58 * while reading a directory (see cc65 readdir() doc for more).
60 if (_DE_ISDIR (ent->d_type)) {
61 subdirs = realloc (subdirs, FILENAME_MAX * (dirnum + 1));
62 strcpy (subdirs + FILENAME_MAX * dirnum++, ent->d_name);
67 for (num = 0; num < dirnum; ++num) {
68 printdir (subdirs + FILENAME_MAX * num);
79 char devicedir[FILENAME_MAX];
81 /* Calling getfirstdevice()/getnextdevice() does _not_ turn on the motor
82 * of a drive-type device and does _not_ check for a disk in the drive.
84 device = getfirstdevice ();
85 while (device != INVALID_DEVICE) {
86 printf ("Device %d:\n", device);
88 /* Calling getdevicedir() _does_ check for a (formatted) disk in a
89 * floppy-disk-type device and returns NULL if that check fails.
91 if (getdevicedir (device, devicedir, sizeof (devicedir))) {
97 device = getnextdevice (device);