Use relative file path

Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
Mahyar Koshkouei
2017-02-04 18:31:17 +00:00
parent 6e7de0df65
commit 4933cf554e

View File

@@ -130,20 +130,11 @@ int main(int argc, char **argv)
int audioFileNum = 0; int audioFileNum = 0;
DIR *dp; DIR *dp;
struct dirent *ep; struct dirent *ep;
char* wd = getcwd(NULL, 0);
if(wd == NULL) dp = opendir(".");
{
err_print("wd");
goto err;
}
dp = opendir(wd);
if(dp != NULL) if(dp != NULL)
{ {
char* file = NULL;
while((ep = readdir(dp)) != NULL) while((ep = readdir(dp)) != NULL)
{ {
if(audioFileNum == fileNum - 1) if(audioFileNum == fileNum - 1)
@@ -165,24 +156,12 @@ int main(int argc, char **argv)
err_print("Unable to list directory."); err_print("Unable to list directory.");
closedir(dp); closedir(dp);
free(wd);
continue; continue;
} }
if(asprintf(&file, "%s%s", wd, ep->d_name) == -1) consoleSelect(&topScreen);
{ playFile(ep->d_name);
err_print("Constructing file name failed."); consoleSelect(&bottomScreen);
file = NULL;
}
else
{
consoleSelect(&topScreen);
playFile(file);
consoleSelect(&bottomScreen);
}
free(file);
free(wd);
if(closedir(dp) != 0) if(closedir(dp) != 0)
err_print("Closing directory failed."); err_print("Closing directory failed.");
@@ -293,13 +272,9 @@ int getNumberFiles(void)
{ {
DIR *dp; DIR *dp;
struct dirent *ep; struct dirent *ep;
char* wd = getcwd(NULL, 0);
int ret = 0; int ret = 0;
if(wd == NULL) if((dp = opendir(".")) == NULL)
goto err;
if((dp = opendir(wd)) == NULL)
goto err; goto err;
while((ep = readdir(dp)) != NULL) while((ep = readdir(dp)) != NULL)