1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-12-04 14:46:31 -05:00

Store playlist location alongside playlists

This commit is contained in:
Moritz Grimm 2022-09-10 19:26:18 +02:00
parent b0a2b8f072
commit 4c4bf8ffce
3 changed files with 26 additions and 0 deletions

View File

@ -27,6 +27,9 @@
#endif
#include <errno.h>
#if defined(HAVE_LIBGEN_H)
# include <libgen.h>
#endif /* HAVE_LIBGEN_H */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@ -45,6 +48,7 @@
struct playlist {
char *filename;
char *location;
char **list;
size_t size;
size_t num;
@ -62,9 +66,15 @@ static struct playlist *
_playlist_create(const char *filename)
{
struct playlist *pl;
char *tmp;
pl = xcalloc(1UL, sizeof(*pl));
pl->filename = xstrdup(filename);
tmp = xstrdup(filename);
pl->location = xstrdup(dirname(tmp));
xfree(tmp);
if (NULL == pl->location)
pl->location = xstrdup(".");
return (pl);
}
@ -289,6 +299,10 @@ playlist_free(struct playlist **pl_p)
xfree(pl->filename);
pl->filename = NULL;
}
if (pl->location != NULL) {
xfree(pl->location);
pl->location = NULL;
}
if (pl->list != NULL) {
if (pl->size > 0) {
@ -437,3 +451,9 @@ playlist_shuffle(struct playlist *pl)
pl->list[i] = temp;
}
}
const char *
playlist_get_location(struct playlist *pl)
{
return (pl->location);
}

View File

@ -101,4 +101,9 @@ int playlist_reread(playlist_t *);
*/
void playlist_shuffle(playlist_t);
/*
* Return the path where the playlist file or program is located on disk.
*/
const char * playlist_get_location(playlist_t);
#endif /* __PLAYLIST_H__ */

View File

@ -15,6 +15,7 @@ START_TEST(test_playlist_file)
ck_assert_ptr_eq(playlist_read("nonexistent.txt"), NULL);
p = playlist_read(SRCDIR "/playlist.txt");
ck_assert_ptr_ne(p, NULL);
ck_assert_str_eq(playlist_get_location(p), SRCDIR);
ck_assert_uint_gt(playlist_get_num_items(p), 0);
ck_assert_str_eq(playlist_get_next(p), "1.ogg");
playlist_skip_next(p);