song: use songvec_for_each() in songvec_print() / songvec_save()
songvec_for_each() has locking, use it instead of manually iterating over the songvec items.
This commit is contained in:
parent
f0366cc8ca
commit
c47f97e1dc
@ -42,14 +42,14 @@ int song_print_info(struct client *client, Song * song)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
song_print_info_x(Song *song, void *data)
|
||||||
|
{
|
||||||
|
struct client *client = data;
|
||||||
|
return song_print_info(client, song);
|
||||||
|
}
|
||||||
|
|
||||||
int songvec_print(struct client *client, const struct songvec *sv)
|
int songvec_print(struct client *client, const struct songvec *sv)
|
||||||
{
|
{
|
||||||
int i;
|
return songvec_for_each(sv, song_print_info_x, client);
|
||||||
Song **sp = sv->base;
|
|
||||||
|
|
||||||
for (i = sv->nr; --i >= 0;)
|
|
||||||
if (song_print_info(client, *sp++) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -37,28 +37,27 @@ static void song_save_url(FILE *fp, Song * song)
|
|||||||
song->url);
|
song->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void song_save(FILE *fp, Song * song)
|
static int
|
||||||
|
song_save(Song *song, void *data)
|
||||||
{
|
{
|
||||||
|
FILE *fp = data;
|
||||||
|
|
||||||
|
fprintf(fp, SONG_KEY "%s\n", song->url);
|
||||||
|
|
||||||
song_save_url(fp, song);
|
song_save_url(fp, song);
|
||||||
|
|
||||||
if (song->tag != NULL)
|
if (song->tag != NULL)
|
||||||
tag_save(fp, song->tag);
|
tag_save(fp, song->tag);
|
||||||
|
|
||||||
|
fprintf(fp, SONG_MTIME "%li\n", (long)song->mtime);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void songvec_save(FILE *fp, struct songvec *sv)
|
void songvec_save(FILE *fp, struct songvec *sv)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
Song **sp = sv->base;
|
|
||||||
|
|
||||||
fprintf(fp, "%s\n", SONG_BEGIN);
|
fprintf(fp, "%s\n", SONG_BEGIN);
|
||||||
|
songvec_for_each(sv, song_save, fp);
|
||||||
for (i = sv->nr; --i >= 0; ) {
|
|
||||||
Song *song = *sp++;
|
|
||||||
fprintf(fp, "%s%s\n", SONG_KEY, song->url);
|
|
||||||
song_save(fp, song);
|
|
||||||
fprintf(fp, "%s%li\n", SONG_MTIME, (long)song->mtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp, "%s\n", SONG_END);
|
fprintf(fp, "%s\n", SONG_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user