diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-03 04:40:05 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-03 04:40:05 +0000 |
commit | b6a13b6cdf02bd017c887eb8b7224b5e967e1bb6 (patch) | |
tree | de977b88166502458286b9529b8e3124dbcfd2a7 /src/common/util.c | |
parent | 33b2abbc9005ef993bec3fc411bade881b125c11 (diff) | |
download | tor-b6a13b6cdf02bd017c887eb8b7224b5e967e1bb6.tar tor-b6a13b6cdf02bd017c887eb8b7224b5e967e1bb6.tar.gz |
Add directory listing functions to util.[ch]. Watch the features creep!
svn:r4906
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index e2bfadebe..67d62aedd 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -19,10 +19,13 @@ const char util_c_id[] = "$Id$"; #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 @@ char *expand_filename(const char *filename) } } +/** 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 * ===== */ |