diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-11 23:04:36 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-12 05:27:33 -0700 |
commit | e018b35b0d99d24e1f3779fd51c07154b370eca9 (patch) | |
tree | 236e61c9c8e69317079e8c2796f6aa5c875bc763 /src/directory_print.c | |
parent | 4111d84ad5b72f871d35f76a47765c138a201611 (diff) | |
download | mpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.tar.gz mpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.tar.xz mpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.zip |
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.
Diffstat (limited to 'src/directory_print.c')
-rw-r--r-- | src/directory_print.c | 22 |
1 files changed, 10 insertions, 12 deletions
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; } |