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:
authorDanny Smith <dannysmith@users.sourceforge.net>2002-06-13 14:20:48 +0400
committerDanny Smith <dannysmith@users.sourceforge.net>2002-06-13 14:20:48 +0400
commitdc8971488e7c174ab4084cbdb0a8f12c39b738d7 (patch)
treed679387fa379b6d5feb9756bdd7237347614453b /winsup/mingw/samples
parent5f74ae83e5fba1ceb73a8d822cbe2b48c619127f (diff)
* include/_mingw.h: Increment version to 2.0.
* Makefile.in: Ditto. Merge in mingwex branch.
Diffstat (limited to 'winsup/mingw/samples')
-rw-r--r--winsup/mingw/samples/dirent/wtest.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/winsup/mingw/samples/dirent/wtest.c b/winsup/mingw/samples/dirent/wtest.c
new file mode 100644
index 000000000..798544374
--- /dev/null
+++ b/winsup/mingw/samples/dirent/wtest.c
@@ -0,0 +1,98 @@
+/*
+ * A test which demonstrates the use of _wopendir and related
+ * wide char functions declared in dirent.h.
+ *
+ * TODO: Make this _UNICODE neutral using tchar.h mappings.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+
+int
+main (int argc, char* argv[])
+{
+ int i;
+ struct _wdirent* de;
+ _WDIR* dir;
+ long lPos;
+
+ if (argc == 2)
+ {
+ size_t len = strlen(argv[1]) + 1;
+ wchar_t* wpath = (wchar_t*) malloc(len *sizeof(wchar_t));
+ mbstowcs(wpath, argv[1], len);
+ wprintf (L"Opening directory \"%s\"\n", wpath);
+ dir = _wopendir(wpath);
+ free (wpath);
+ }
+ else
+ {
+ wprintf (L"Opening \".\"\n");
+ dir = _wopendir(L".");
+ }
+
+ if (!dir)
+ {
+ wprintf (L"Directory open failed!\n");
+ if (errno)
+ {
+ wprintf (L"Error : %S\n", strerror(errno));
+ }
+ return 1;
+ }
+
+ i = 0;
+ lPos = -1;
+
+ while ((de = _wreaddir (dir)))
+ {
+ i++;
+ wprintf (L"%d : \"%s\" (tell %ld)\n", i, de->d_name,
+ _wtelldir(dir));
+
+ if (i == 3)
+ {
+ wprintf (L"We will seek here later.\n");
+ lPos = _wtelldir (dir);
+ }
+ }
+
+ printf ("Rewind directory.\n");
+ _wrewinddir (dir);
+
+ if ((de = _wreaddir (dir)))
+ {
+ wprintf (L"First entry : \"%s\"\n", de->d_name);
+ }
+ else
+ {
+ wprintf (L"Empty directory.\n");
+ }
+
+ if (lPos != -1)
+ {
+ wprintf (L"Seeking to fourth entry.\n");
+ _wseekdir (dir, lPos);
+
+ if ((de = _wreaddir (dir)))
+ {
+ wprintf (L"Fourth entry : \"%s\"\n", de->d_name);
+ }
+ else
+ {
+ wprintf (L"No fourth entry.\n");
+ }
+ }
+ else
+ {
+ wprintf (L"Seek position is past end of directory.\n");
+ }
+
+ wprintf (L"Closing directory.\n");
+ _wclosedir (dir);
+return 0;
+}
+