From e018b35b0d99d24e1f3779fd51c07154b370eca9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Oct 2008 23:04:36 -0700 Subject: dirvec: use dirvec_for_each where it makes sense This way we can introduce locking to allow safe traversals from the main thread while we're updating. --- src/directory_print.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/directory_print.c') diff --git a/src/directory_print.c b/src/directory_print.c index 1c30f1608..d7b42ec59 100644 --- a/src/directory_print.c +++ b/src/directory_print.c @@ -23,25 +23,23 @@ #include "songvec.h" #include "myfprintf.h" -static int dirvec_print(int fd, const struct dirvec *dv) +static int directory_print_info(struct directory *dir, int fd) { - size_t i; - - for (i = 0; i < dv->nr; ++i) { - if (fdprintf(fd, DIRECTORY_DIR "%s\n", - directory_get_path(dv->base[i])) < 0) - return -1; - } + return fdprintf(fd, DIRECTORY_DIR "%s\n", directory_get_path(dir)); +} - return 0; +static int directory_print_info_x(struct directory *dir, void *data) +{ + return directory_print_info(dir, (int)(size_t)data); } int directory_print(int fd, const struct directory *dir) { - if (dirvec_print(fd, &dir->children) < 0) + void *arg = (void *)(size_t)fd; + + if (dirvec_for_each(&dir->children, directory_print_info_x, arg) < 0) return -1; - if (songvec_for_each(&dir->songs, song_print_info_x, - (void *)(size_t)fd) < 0) + if (songvec_for_each(&dir->songs, song_print_info_x, arg) < 0) return -1; return 0; } -- cgit v1.2.3