[or-cvs] Add directory listing functions to util.[ch]. Watch the fe...
Nick Mathewson
nickm at seul.org
Sat Sep 3 04:40:07 UTC 2005
Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv30407/src/common
Modified Files:
util.c util.h
Log Message:
Add directory listing functions to util.[ch]. Watch the features creep!
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.217
retrieving revision 1.218
diff -u -d -r1.217 -r1.218
--- util.c 26 Aug 2005 18:40:44 -0000 1.217
+++ util.c 3 Sep 2005 04:40:05 -0000 1.218
@@ -19,10 +19,13 @@
#include "log.h"
#include "crypto.h"
#include "torint.h"
+#include "container.h"
#ifdef MS_WINDOWS
#include <io.h>
#include <direct.h>
+#else
+#include <dirent.h>
#endif
#ifdef HAVE_CTYPE_H
@@ -1106,6 +1109,29 @@
}
}
+/** Return a new list containing the filenames in the directory <b>dirname</b>.
+ * Return NULL on error or if <b>dirname</b> is not a directory.
+ */
+smartlist_t *
+tor_listdir(const char *dirname)
+{
+ DIR *d;
+ smartlist_t *result;
+ struct dirent *de;
+ if (!(d = opendir(dirname)))
+ return NULL;
+
+ result = smartlist_create();
+ while ((de = readdir(d))) {
+ if (!strcmp(de->d_name, ".") ||
+ !strcmp(de->d_name, ".."))
+ continue;
+ smartlist_add(result, tor_strdup(de->d_name));
+ }
+ closedir(d);
+ return result;
+}
+
/* =====
* Net helpers
* ===== */
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -d -r1.136 -r1.137
--- util.h 26 Aug 2005 07:37:07 -0000 1.136
+++ util.h 3 Sep 2005 04:40:05 -0000 1.137
@@ -123,6 +123,7 @@
char *read_file_to_str(const char *filename, int bin);
char *parse_line_from_str(char *line, char **key_out, char **value_out);
char *expand_filename(const char *filename);
+struct smartlist_t *tor_listdir(const char *dirname);
/* Net helpers */
int is_internal_IP(uint32_t ip);
More information about the tor-commits
mailing list