X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=afs_common.c;fp=afs_common.c;h=0000000000000000000000000000000000000000;hb=8978f426314b107c55a652e0151397fdab2f003e;hp=c45b3d90f18b3443ba82e379d1c94ff8e4837f3e;hpb=08a1de75a3a83c728d97a3c4ff182553adbda8cc;p=paraslash.git diff --git a/afs_common.c b/afs_common.c deleted file mode 100644 index c45b3d90..00000000 --- a/afs_common.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2005-2007 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ - - -/** \file afs_common.c Functions common to all audio file selectors. */ - -#include -#include - - -#include "para.h" -#include "error.h" -#include "string.h" -#include "fd.h" -#include "server.cmdline.h" -#include "afh.h" -#include "afs.h" -#include "server.h" -#include "vss.h" -#include /* readdir() */ -#include /* stat */ -#include /* mode_t */ - -/** - * Traverse the given directory recursively. - * - * \param dirname The directory to traverse. - * \param f The function to call for each entry. - * - * For each regular file whose filename ends in .yyy, where yyy is a supported - * audio format, the supplied function \a f is called. The directory and - * filename component of the regular file are passed to \a f. - * - * \return On success, 1 is returned. Otherwise, this function returns a - * negative value which indicates the kind of the error. - */ -int find_audio_files(const char *dirname, int (*f)(const char *, const char *)) -{ - DIR *dir = NULL; - int ret, ret2, cwd_fd; - struct dirent *entry; - - 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; - if (!strcmp(entry->d_name, "..")) - continue; - ret = -E_LSTAT; - if (lstat(entry->d_name, &s) == -1) - continue; - m = s.st_mode; - if (!S_ISREG(m) && !S_ISDIR(m)) /* skip links, sockets, ... */ - continue; - if (S_ISREG(m)) { /* regular file */ - if (guess_audio_format(entry->d_name) < 0) - continue; - ret = f(dirname, entry->d_name); - if (ret < 0) - goto out; - continue; - } - /* directory */ - tmp = make_message("%s/%s", dirname, entry->d_name); - ret = find_audio_files(tmp, f); - free(tmp); - if (ret < 0) - goto out; - } - ret = 1; -out: - if (dir) - closedir(dir); - 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)); - return ret; -}