mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Add directory listing functions to util.[ch]. Watch the features creep!
svn:r4906
This commit is contained in:
parent
33b2abbc90
commit
b6a13b6cdf
@ -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
|
||||
* ===== */
|
||||
|
@ -123,6 +123,7 @@ int write_bytes_to_file(const char *fname, const char *str, size_t len,
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user