From e92356cb369f764b7b99f58d8ab585b8388a7c05 Mon Sep 17 00:00:00 2001 From: uz Date: Wed, 6 Jun 2012 18:31:58 +0000 Subject: [PATCH] Added the test program for the POSIX directory routines. git-svn-id: svn://svn.cc65.org/cc65/trunk@5686 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- testcode/lib/dir-test.c | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 testcode/lib/dir-test.c diff --git a/testcode/lib/dir-test.c b/testcode/lib/dir-test.c new file mode 100644 index 000000000..479caa335 --- /dev/null +++ b/testcode/lib/dir-test.c @@ -0,0 +1,96 @@ + +/* + first test for posix directory routines for the c64 + kludges: + - currently uses cbm_open, which conflicts with standard i/o, + which in turn makes it infact kindof unuseable. this can + be easily changed however, since the only reason not to use + open/read was that it currently appends ,u,r to filenames + - the offset in current dir stream should better be calculated + from the values returned by "read". + - the type flag isnt filled in atm. + - scandir/alphasort/versionsort is missing + - some bits are currently untested (ie, unused in the testprogram) + 27/02/2003 gpz +*/ + +#include +#include +#include +#include +#include +#include +#include + + +int main(void) +{ + char* name = "."; + unsigned char go = 0; + register DIR *D; + struct dirent* E; + + D = opendir (name); + if (D == 0) { + printf("error opening %s: %s\n", name, strerror (errno)); + return 1; + } + + /* Explain usage and wait for a key */ + printf ("Use the following keys:\n" + " g -> go ahead without stop\n" + " q -> quit directory listing\n" + " r -> return to last entry\n" + " s -> seek back to start\n" + "Press any key to start ...\n"); + cgetc (); + + /* Open the directory */ + D = opendir (name); + if (D == 0) { + printf("error opening %s: %s\n", name, strerror (errno)); + return 1; + } + + /* Output the directory */ + errno = 0; + printf("contents of \"%s\":\n", name); + while ((E = readdir (D)) != 0) { + printf ("dirent.d_name[] : \"%s\"\n", E->d_name); + printf ("dirent.d_blocks : %10u\n", E->d_blocks); + printf ("dirent.d_type : %10d\n", E->d_type); + printf ("telldir() : %10lu\n", telldir (D)); + printf ("---\n"); + if (!go) { + switch (cgetc ()) { + case 'g': + go = 1; + break; + + case 'q': + goto done; + + case 'r': + seekdir (D, E->d_off); + break; + + case 's': + rewinddir (D); + break; + + } + } + } + +done: + if (errno == 0) { + printf ("Done\n"); + } else { + printf("Done: %d (s)\n", errno, strerror (errno)); + } + + /* Close the directory */ + closedir (D); + + return 0; +} -- 2.39.5