osx_write.c: Add doxygen description for struct private_osx_write_data
[paraslash.git] / db.c
diff --git a/db.c b/db.c
index d97a6e0e917ffd8b3662ba96d13bbcd37aadefd3..8b06672606e50009004bd9dcf89625425295035b 100644 (file)
--- a/db.c
+++ b/db.c
@@ -17,7 +17,7 @@
  */
 
 
-/** \file db.c functions common to all database tools. */
+/** \file db.c functions common to all audio file selectors */
 
 #include "server.cmdline.h"
 #include "server.h"
 #include "error.h"
 #include "string.h"
 
-/*
- * return 1 if name matches any supported audio format
- */
-static int match_audio_file_name(char *name)
-{
-       int i, len = strlen(name);
-       const char *pattern[] = {SUPPORTED_AUDIO_FORMATS_ARRAY};
-
-       for (i = 0; pattern[i]; i++) {
-               const char *p = pattern[i];
-               int plen = strlen(p);
-               if (len < plen + 1)
-                       continue;
-               if (name[len - plen - 1] != '.')
-                       continue;
-               if (strcasecmp(name + len - plen, p))
-                       continue;
-               return 1;
-       }
-       return 0;
-}
-
 /**
  * traverse the given directory recursively
  *
@@ -97,14 +75,15 @@ int find_audio_files(const char *dirname, int (*f)(const char *, const char *))
                        continue;
                ret = -E_LSTAT;
                if (lstat(entry->d_name, &s) == -1)
-                       goto out;
+                       continue;
                m = s.st_mode;
                if (!S_ISREG(m) && !S_ISDIR(m)) /* skip links, sockets, ... */
                        continue;
                if (S_ISREG(m)) { /* regular file */
-                       if (!match_audio_file_name(entry->d_name))
+                       if (guess_audio_format(entry->d_name) < 0)
                                continue;
-                       if (f(dirname, entry->d_name) < 0)
+                       ret = f(dirname, entry->d_name);
+                       if (ret < 0)
                                goto out;
                        continue;
                }
@@ -123,6 +102,6 @@ out:
                ret = -E_CHDIR;
        close(cwd_fd);
        if (ret < 0)
-               PARA_ERROR_LOG("ret = %x\n", -ret);
+               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
        return ret;
 }