summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2011-02-23 17:57:08 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2011-03-03 21:38:52 +0200
commit5e0a163886f825983c5bfcd4181e6498b0f3e0f2 (patch)
treea2d6b359dc276c69a1e538ee435f19bd3a768c85
parent962eec0440ad65a71c09a9e206e110c62d9de3c8 (diff)
downloadmpv-5e0a163886f825983c5bfcd4181e6498b0f3e0f2.tar.bz2
mpv-5e0a163886f825983c5bfcd4181e6498b0f3e0f2.tar.xz
tl_matroska.c: move the find_files() function here
Move the find_files() function from findfiles.c to tl_matroska.c. Delete the findfiles.c file. Add a check against opendir() failure in find_files().
-rw-r--r--Makefile1
-rw-r--r--mpcommon.h2
-rw-r--r--osdep/findfiles.c77
-rw-r--r--osdep/findfiles.h2
-rw-r--r--timeline/tl_matroska.c61
5 files changed, 60 insertions, 83 deletions
diff --git a/Makefile b/Makefile
index 9c8beb0335..90802b0ae2 100644
--- a/Makefile
+++ b/Makefile
@@ -423,7 +423,6 @@ SRCS_COMMON = asxparser.c \
libmpdemux/yuv4mpeg.c \
libmpdemux/yuv4mpeg_ratio.c \
libvo/osd.c \
- osdep/findfiles.c \
osdep/numcores.c \
osdep/$(GETCH) \
osdep/$(TIMER) \
diff --git a/mpcommon.h b/mpcommon.h
index 891331293f..bc35934e41 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -24,6 +24,8 @@
#define ROUND(x) ((int)((x) < 0 ? (x) - 0.5 : (x) + 0.5))
+#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
+
extern const char *mplayer_version;
#endif /* MPLAYER_MPCOMMON_H */
diff --git a/osdep/findfiles.c b/osdep/findfiles.c
deleted file mode 100644
index e35174dfd4..0000000000
--- a/osdep/findfiles.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <dirent.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "talloc.h"
-#include "path.h"
-#include "bstr.h"
-
-char **find_files(const char *original_file, const char *suffix,
- int *num_results_ptr)
-{
- void *tmpmem = talloc_new(NULL);
- char *basename = mp_basename(original_file);
- struct bstr directory = mp_dirname(original_file);
- char **results = talloc_size(NULL, 0);
- char *dir_zero = bstrdup0(tmpmem, directory);
- DIR *dp = opendir(dir_zero);
- struct dirent *ep;
- char ***names_by_matchlen = talloc_array(tmpmem, char **,
- strlen(basename) + 1);
- memset(names_by_matchlen, 0, talloc_get_size(names_by_matchlen));
- int num_results = 0;
- while ((ep = readdir(dp))) {
- int suffix_offset = strlen(ep->d_name) - strlen(suffix);
- // name must end with suffix
- if (suffix_offset < 0 || strcmp(ep->d_name + suffix_offset, suffix))
- continue;
- // don't list the original name
- if (!strcmp(ep->d_name, basename))
- continue;
-
- char *name = mp_path_join(results, directory, BSTR(ep->d_name));
- char *s1 = ep->d_name;
- char *s2 = basename;
- int matchlen = 0;
- while (*s1 && *s1++ == *s2++)
- matchlen++;
- int oldcount = talloc_get_size(names_by_matchlen[matchlen]) /
- sizeof(char **);
- names_by_matchlen[matchlen] = talloc_realloc(names_by_matchlen,
- names_by_matchlen[matchlen],
- char *, oldcount + 1);
- names_by_matchlen[matchlen][oldcount] = name;
- num_results++;
- }
- closedir(dp);
- results = talloc_realloc(NULL, results, char *, num_results);
- char **resptr = results;
- for (int i = strlen(basename); i >= 0; i--) {
- char **p = names_by_matchlen[i];
- for (int j = 0; j < talloc_get_size(p) / sizeof(char *); j++)
- *resptr++ = p[j];
- }
- assert(resptr == results + num_results);
- talloc_free(tmpmem);
- *num_results_ptr = num_results;
- return results;
-}
diff --git a/osdep/findfiles.h b/osdep/findfiles.h
deleted file mode 100644
index 97443e7319..0000000000
--- a/osdep/findfiles.h
+++ /dev/null
@@ -1,2 +0,0 @@
-char **find_files(const char *original_file, const char *suffix,
- int *num_results_ptr);
diff --git a/timeline/tl_matroska.c b/timeline/tl_matroska.c
index 3c4b34d19d..46d0e33a45 100644
--- a/timeline/tl_matroska.c
+++ b/timeline/tl_matroska.c
@@ -19,6 +19,8 @@
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
+#include <assert.h>
+#include <dirent.h>
#include <libavutil/common.h>
#include "talloc.h"
@@ -26,7 +28,60 @@
#include "mp_core.h"
#include "mp_msg.h"
#include "libmpdemux/demuxer.h"
-#include "osdep/findfiles.h"
+#include "path.h"
+#include "bstr.h"
+#include "mpcommon.h"
+
+static char **find_files(const char *original_file, const char *suffix)
+{
+ void *tmpmem = talloc_new(NULL);
+ char *basename = mp_basename(original_file);
+ struct bstr directory = mp_dirname(original_file);
+ char **results = talloc_size(NULL, 0);
+ char *dir_zero = bstrdup0(tmpmem, directory);
+ DIR *dp = opendir(dir_zero);
+ if (!dp) {
+ talloc_free(tmpmem);
+ return results;
+ }
+ struct dirent *ep;
+ char ***names_by_matchlen = talloc_zero_array(tmpmem, char **,
+ strlen(basename) + 1);
+ int num_results = 0;
+ while ((ep = readdir(dp))) {
+ int suffix_offset = strlen(ep->d_name) - strlen(suffix);
+ // name must end with suffix
+ if (suffix_offset < 0 || strcmp(ep->d_name + suffix_offset, suffix))
+ continue;
+ // don't list the original name
+ if (!strcmp(ep->d_name, basename))
+ continue;
+
+ char *name = mp_path_join(results, directory, BSTR(ep->d_name));
+ char *s1 = ep->d_name;
+ char *s2 = basename;
+ int matchlen = 0;
+ while (*s1 && *s1++ == *s2++)
+ matchlen++;
+ int oldcount = MP_TALLOC_ELEMS(names_by_matchlen[matchlen]);
+ names_by_matchlen[matchlen] = talloc_realloc(names_by_matchlen,
+ names_by_matchlen[matchlen],
+ char *, oldcount + 1);
+ names_by_matchlen[matchlen][oldcount] = name;
+ num_results++;
+ }
+ closedir(dp);
+ results = talloc_realloc(NULL, results, char *, num_results);
+ char **resptr = results;
+ for (int i = strlen(basename); i >= 0; i--) {
+ char **p = names_by_matchlen[i];
+ for (int j = 0; j < talloc_get_size(p) / sizeof(char *); j++)
+ *resptr++ = p[j];
+ }
+ assert(resptr == results + num_results);
+ talloc_free(tmpmem);
+ return results;
+}
static int find_ordered_chapter_sources(struct MPContext *mpctx,
struct content_source *sources,
@@ -44,8 +99,8 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx,
} else {
mp_msg(MSGT_CPLAYER, MSGL_INFO, "Will scan other files in the "
"same directory to find referenced sources.\n");
- filenames = find_files(mpctx->demuxer->filename, ".mkv",
- &num_filenames);
+ filenames = find_files(mpctx->demuxer->filename, ".mkv");
+ num_filenames = MP_TALLOC_ELEMS(filenames);
}
}