map

minimalistic audio player
git clone https://porkepik.fr/map
Log | Files | Refs | README | LICENSE

commit f2356b295a393299a323fc406772c0df6711f37c
parent 00be142a916b219fd43e1bc23e4b845a20b75299
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Tue, 27 Aug 2019 03:03:37 +0200

reduce build_track_list function

Diffstat:
Mmap.c | 12+++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/map.c b/map.c @@ -255,18 +255,12 @@ trackcmp(const void *a, const void *b) static void build_track_list(struct track **tracks, char **tracklist) { - int i, track_len; - - for (i = 0; i < ntracks; i++) { - track_len = snprintf(NULL, 0, "%9d:%02d %s\n", - tracks[i]->length / 60, tracks[i]->length % 60, - tracks[i]->name); - - tracklist[i] = malloc(track_len + 1); + for (int i = 0; i < ntracks; i++) { + tracklist[i] = malloc(strlen(tracks[i]->name) + 30); if (!tracklist[i]) errx(1, "malloc failure"); - sprintf(tracklist[i], "%9d:%02d %s\n", tracks[i]->length / 60, + sprintf(tracklist[i], "%8d:%02d %s\n", tracks[i]->length / 60, tracks[i]->length % 60, tracks[i]->name); } }