[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Implement tor_listdir on windows. Untested.



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv26730/src/common

Modified Files:
	util.c 
Log Message:
Implement tor_listdir on windows.  Untested.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.219
retrieving revision 1.220
diff -u -d -r1.219 -r1.220
--- util.c	8 Sep 2005 18:33:51 -0000	1.219
+++ util.c	9 Sep 2005 21:29:23 -0000	1.220
@@ -1125,8 +1125,32 @@
 smartlist_t *
 tor_listdir(const char *dirname)
 {
-  DIR *d;
   smartlist_t *result;
+#ifdef MS_WINDOWS
+  char *pattern;
+  HANDLE handle;
+  WIN32_FIND_DATA findData;
+  size_t pattern_len = strlen(dirname)+16;
+  pattern = tor_malloc(pattern_len);
+  tor_snprintf(pattern, pattern_len, "%s\\*", dirname);
+  if (!(handle = FindFirstFile(pattern, &findData))) {
+    tor_free(pattern);
+    return NULL;
+  }
+  result = smartlist_create();
+  while (1) {
+    smartlist_add(findData.cFileName);
+    if (!FindNextFile(handle, &findData)) {
+      if (GetLastError() != ERROR_NO_MORE_FILES) {
+        log_fn(LOG_WARN, "Error reading directory.");
+      }
+      break;
+    }
+  }
+  FindClose(handle);
+  tor_free(pattern);
+#else
+  DIR *d;
   struct dirent *de;
   if (!(d = opendir(dirname)))
     return NULL;
@@ -1139,6 +1163,7 @@
     smartlist_add(result, tor_strdup(de->d_name));
   }
   closedir(d);
+#endif
   return result;
 }