diff options
Diffstat (limited to 'winsup/mingw/samples/dirent')
-rw-r--r-- | winsup/mingw/samples/dirent/jamfile | 3 | ||||
-rw-r--r-- | winsup/mingw/samples/dirent/test.c | 91 |
2 files changed, 94 insertions, 0 deletions
diff --git a/winsup/mingw/samples/dirent/jamfile b/winsup/mingw/samples/dirent/jamfile new file mode 100644 index 000000000..4bfdc2461 --- /dev/null +++ b/winsup/mingw/samples/dirent/jamfile @@ -0,0 +1,3 @@ +
+Main test.exe : test.c ;
+
diff --git a/winsup/mingw/samples/dirent/test.c b/winsup/mingw/samples/dirent/test.c new file mode 100644 index 000000000..bb4629fea --- /dev/null +++ b/winsup/mingw/samples/dirent/test.c @@ -0,0 +1,91 @@ +/*
+ * A test which demonstrates the use of opendir and related functions
+ * declared in dirent.h.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <dirent.h>
+
+int
+main (int argc, char* argv[])
+{
+ int i;
+ struct dirent* de;
+ DIR* dir;
+ long lPos;
+
+ if (argc == 2)
+ {
+ printf ("Opening directory \"%s\"\n", argv[1]);
+ dir = opendir(argv[1]);
+ }
+ else
+ {
+ printf ("Opening \".\"\n");
+ dir = opendir(".");
+ }
+
+ if (!dir)
+ {
+ printf ("Directory open failed!\n");
+ if (errno)
+ {
+ printf ("Error : %s\n", strerror(errno));
+ }
+ return 1;
+ }
+
+ i = 0;
+ lPos = -1;
+
+ while (de = readdir (dir))
+ {
+ i++;
+ printf ("%d : \"%s\" (tell %ld)\n", i, de->d_name,
+ telldir(dir));
+
+ if (i == 3)
+ {
+ printf ("We will seek here later.\n");
+ lPos = telldir (dir);
+ }
+ }
+
+ printf ("Rewind directory.\n");
+ rewinddir (dir);
+
+ if (de = readdir (dir))
+ {
+ printf ("First entry : \"%s\"\n", de->d_name);
+ }
+ else
+ {
+ printf ("Empty directory.\n");
+ }
+
+ if (lPos != -1)
+ {
+ printf ("Seeking to fourth entry.\n");
+ seekdir (dir, lPos);
+
+ if (de = readdir (dir))
+ {
+ printf ("Fourth entry : \"%s\"\n", de->d_name);
+ }
+ else
+ {
+ printf ("No fourth entry.\n");
+ }
+ }
+ else
+ {
+ printf ("Seek position is past end of directory.\n");
+ }
+
+ printf ("Closing directory.\n");
+ closedir (dir);
+}
+
|