1 /* GStreamer Split Source Utility Functions
2 * Copyright (C) 2011 Collabora Ltd. <tim.muller@collabora.co.uk>
3 * Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
27 #include "gstsplitutils.h"
28 #include "patternspec.h"
31 gst_split_util_array_sortfunc (gchar ** a, gchar ** b)
33 return strcmp (*a, *b);
37 gst_split_util_find_files (const gchar * dirname,
38 const gchar * basename, GError ** err)
45 if (dirname == NULL || basename == NULL)
46 goto invalid_location;
48 GST_INFO ("checking in directory '%s' for pattern '%s'", dirname, basename);
50 dir = g_dir_open (dirname, 0, err);
54 if (DEFAULT_PATTERN_MATCH_MODE == MATCH_MODE_UTF8 &&
55 !g_utf8_validate (basename, -1, NULL)) {
59 /* mode will be AUTO on linux/unix and UTF8 on win32 */
60 pspec = pattern_spec_new (basename, DEFAULT_PATTERN_MATCH_MODE);
62 files = g_ptr_array_new ();
64 while ((name = g_dir_read_name (dir))) {
65 GST_TRACE ("check: %s", name);
66 if (pattern_match_string (pspec, name)) {
67 GST_DEBUG ("match: %s", name);
68 g_ptr_array_add (files, g_build_filename (dirname, name, NULL));
75 g_ptr_array_sort (files, (GCompareFunc) gst_split_util_array_sortfunc);
76 g_ptr_array_add (files, NULL);
78 pattern_spec_free (pspec);
81 return (gchar **) g_ptr_array_free (files, FALSE);
86 g_set_error_literal (err, G_FILE_ERROR, G_FILE_ERROR_INVAL,
87 "No filename specified.");
93 g_set_error_literal (err, G_FILE_ERROR, G_FILE_ERROR_INVAL,
94 "Filename pattern must be UTF-8 on Windows.");
99 pattern_spec_free (pspec);
101 g_set_error_literal (err, G_FILE_ERROR, G_FILE_ERROR_NOENT,
102 "Found no files matching the pattern.");