map

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

commit fb77c4976fc9bcaab33af6d7273a87dd0926bdc5
parent f2356b295a393299a323fc406772c0df6711f37c
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Tue, 27 Aug 2019 15:07:34 +0200

simplify getting current directory

Diffstat:
Mmap.c | 28+++++-----------------------
1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/map.c b/map.c @@ -265,28 +265,6 @@ build_track_list(struct track **tracks, char **tracklist) } } -static char * -getcurrentdir(int argc, char **argv) -{ - char *curdir = NULL; - - if (argc > 1) { - curdir = malloc(strlen(argv[1]) + 2); - if (!curdir) - errx(1, "malloc failure"); - strcpy(curdir, argv[1]); - if (!strend(curdir, "/")) - strcat(curdir, "/"); - } else { - curdir = malloc(strlen("./") + 1); - if (!curdir) - errx(1, "malloc failure"); - strcpy(curdir, "./"); - } - - return curdir; -} - static void open_track(struct track track) { @@ -423,7 +401,11 @@ main(int argc, char **argv) int trackid = 0; struct player player; - player.curdir = getcurrentdir(argc, argv); + if (argc > 1) + player.curdir = argv[1]; + else + player.curdir = "./"; + struct track **tracks = get_tracks(player.curdir); if (ntracks == 0) errx(1, "No audio files found in %s", player.curdir);