Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-02-17 22:38:33 +0300
committerChristopher Faylor <me@cgf.cx>2000-02-17 22:38:33 +0300
commit1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch)
treedc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/samples/dirent/test.c
parent369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff)
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/samples/dirent/test.c')
-rw-r--r--winsup/mingw/samples/dirent/test.c91
1 files changed, 91 insertions, 0 deletions
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);
+}
+