summaryrefslogtreecommitdiffstats
path: root/apps/playlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 0b5662b47c..2bdc1f39cc 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -2887,11 +2887,8 @@ int playlist_create_ex(struct playlist_info* playlist,
if (index_buffer)
{
- size_t unit_size = sizeof (*playlist->indices);
-#ifdef HAVE_DIRCACHE
- unit_size += sizeof (*playlist->dcfrefs);
-#endif
- int num_indices = index_buffer_size / unit_size;
+ int num_indices = index_buffer_size /
+ playlist_get_required_bufsz(playlist, false, 1);
if (num_indices > global_settings.max_files_in_playlist)
num_indices = global_settings.max_files_in_playlist;
@@ -3525,6 +3522,26 @@ char *playlist_get_name(const struct playlist_info* playlist, char *buf,
return buf;
}
+/* return size of buffer needed for playlist to initialize num_indices entries */
+size_t playlist_get_required_bufsz(struct playlist_info* playlist,
+ bool include_namebuf,
+ int num_indices)
+{
+ size_t namebuf = 0;
+
+ if (!playlist)
+ playlist = &current_playlist;
+
+ size_t unit_size = sizeof (*playlist->indices);
+ #ifdef HAVE_DIRCACHE
+ unit_size += sizeof (*playlist->dcfrefs);
+ #endif
+ if (include_namebuf)
+ namebuf = AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
+
+ return (num_indices * unit_size) + namebuf;
+}
+
/* Fills info structure with information about track at specified index.
Returns 0 on success and -1 on failure */
int playlist_get_track_info(struct playlist_info* playlist, int index,