diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-10 01:42:42 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-10 01:42:42 +0000 |
commit | d26523e08964277881c3cdf34dafdc046cf3321d (patch) | |
tree | 5377c041a44ae9fc52ade9620e58f351a04a9b05 /src | |
parent | eab048b7f35adc77f0316f72e981cab571233f81 (diff) | |
download | tor-d26523e08964277881c3cdf34dafdc046cf3321d.tar.gz tor-d26523e08964277881c3cdf34dafdc046cf3321d.zip |
Use tor_listdir in test.c instead of duplicating ode.
svn:r4981
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compat.h | 6 | ||||
-rw-r--r-- | src/or/test.c | 62 |
2 files changed, 19 insertions, 49 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 30db44d8ce..686a9345b1 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -128,6 +128,12 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result); /* ===== File compatibility */ int replace_file(const char *from, const char *to); +#ifdef MS_WINDOWS +#define PATH_SEPARATOR "\\" +#else +#define PATH_SEPARATOR "/" +#endif + /* ===== Net compatibility */ #ifdef MS_WINDOWS /** On windows, you have to call close() on fds returned by open(), diff --git a/src/or/test.c b/src/or/test.c index 4b1453660f..9edab2b137 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -74,56 +74,21 @@ get_fname(const char *name) static void remove_directory(void) { -#ifdef MS_WINDOWS - char *pattern; - HANDLE handle; - WIN32_FIND_DATA findData; - - setup_directory(); - pattern = tor_malloc(strlen(temp_dir)+16); - tor_snprintf(pattern, strlen(temp_dir)+16, "%s\\*", temp_dir); - handle = FindFirstFile(pattern, &findData); - if (handle == INVALID_HANDLE_VALUE) { - perror("Can't remove"); - return; + smartlist_t *elements = tor_listdir(temp_dir); + if (elements) { + SMARTLIST_FOREACH(elements, const char *, cp, + { + size_t len = strlen(cp)+strlen(temp_dir)+16; + char *tmp = tor_malloc(len); + tor_snprintf(tmp, len, "%s"PATH_SEPARATOR"%s", temp_dir, cp); + unlink(tmp); + tor_free(tmp); + }); + SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp)); + smartlist_free(elements); } - while (1) { - size_t dlen = strlen(findData.cFileName)+strlen(temp_dir)+16; - char *deleteable = tor_malloc(dlen); - tor_snprintf(deleteable, dlen, "%s\\%s", temp_dir, findData.cFileName); - unlink(deleteable); - tor_free(deleteable); - if (!FindNextFile(handle, &findData)) { - if (GetLastError() != ERROR_NO_MORE_FILES) { - perror("error reading dir"); - } - break; - } - } - FindClose(handle); - tor_free(pattern); -#else - DIR *dirp; - struct dirent *de; - setup_directory(); - if (!(dirp = opendir(temp_dir))) { - perror("Can't open temporary directory to remove files"); - return; - } - while ((de = readdir(dirp)) != NULL) { - /* Only "." and ".." start with ., since we don't create any dotfiles. */ - if (de->d_name[0] == '.') continue; - if (unlink(get_fname(de->d_name))) { - printf("Couldn't remove temprorary file \"%s/%s\"",temp_dir,de->d_name); - perror(""); - } -#if 0 - printf("==%s\n", de->d_name); -#endif - } - closedir(dirp); -#endif rmdir(temp_dir); + } static void @@ -615,7 +580,6 @@ static int _compare_without_first_ch(const void *a, const void **b) { const char *s1 = a, *s2 = *b; - printf("%s v %s\n",s1, s2); return strcasecmp(s1+1, s2); } |