X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afs_common.c;h=17b4e16ff8f43c0b075d0f949bb3a0c7f35a1809;hp=36da960b30d70673b1dfef94c6068a71fa5687c8;hb=769888ee3175ed60df3c23caf51cdad5db33d141;hpb=77264e47dcd6a606ecff2f86f14359f25ab0eba0 diff --git a/afs_common.c b/afs_common.c index 36da960b..17b4e16f 100644 --- a/afs_common.c +++ b/afs_common.c @@ -7,7 +7,14 @@ /** \file afs_common.c Functions common to all audio file selectors. */ +#include +#include + + +#include "para.h" +#include "fd.h" #include "server.cmdline.h" +#include "afh.h" #include "server.h" #include "vss.h" #include /* readdir() */ @@ -32,29 +39,17 @@ int find_audio_files(const char *dirname, int (*f)(const char *, const char *)) { DIR *dir = NULL; + int ret, ret2, cwd_fd; struct dirent *entry; - /* - * Opening the current directory (".") and calling fchdir() to return - * is usually faster and more reliable than saving cwd in some buffer - * and calling chdir() afterwards (see man 3 getcwd). - */ - int cwd_fd = open(".", O_RDONLY); - struct stat s; - int ret; - if (cwd_fd < 0) - return -E_GETCWD; - ret = -E_CHDIR; - if (chdir(dirname) < 0) - goto out; - ret = -E_OPENDIR; - dir = opendir("."); - if (!dir) - goto out; + ret = para_opendir(dirname, &dir, &cwd_fd); + if (ret < 0) + return ret; /* scan cwd recursively */ while ((entry = readdir(dir))) { mode_t m; char *tmp; + struct stat s; if (!strcmp(entry->d_name, ".")) continue; @@ -85,8 +80,9 @@ int find_audio_files(const char *dirname, int (*f)(const char *, const char *)) out: if (dir) closedir(dir); - if (fchdir(cwd_fd) < 0) - ret = -E_CHDIR; + ret2 = fchdir(cwd_fd); + if (ret2 < 0 && ret >= 0) + ret = ret2; close(cwd_fd); if (ret < 0) PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));