3 * Functions copied from glib 2.6 and 2.8
5 * Copyright 2005 David Schleef <ds@schleef.org>
8 /* gfileutils.c - File utility functions
10 * Copyright 2000 Red Hat, Inc.
12 * GLib is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * GLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GLib; see the file COPYING.LIB. If not,
24 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
31 #include <glib/gstdio.h>
36 #include "glib-compat.h"
37 #include "glib-compat-private.h"
43 #include <sys/types.h>
58 #endif /* G_OS_WIN32 */
62 #define G_DIR_SEPARATOR '\\'
63 #define G_DIR_SEPARATOR_S "\\"
64 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
65 #define G_SEARCHPATH_SEPARATOR ';'
66 #define G_SEARCHPATH_SEPARATOR_S ";"
68 #define G_DIR_SEPARATOR '/'
69 #define G_DIR_SEPARATOR_S "/"
70 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
71 #define G_SEARCHPATH_SEPARATOR ':'
72 #define G_SEARCHPATH_SEPARATOR_S ":"
76 #if !GLIB_CHECK_VERSION (2, 8, 0)
78 * g_mkdir_with_parents:
79 * @pathname: a pathname in the GLib file name encoding
80 * @mode: permissions to use for newly created directories
82 * Create a directory if it doesn't already exist. Create intermediate
83 * parent directories as needed, too.
85 * Returns: 0 if the directory already exists, or was successfully
86 * created. Returns -1 if an error occurred, with errno set.
91 g_mkdir_with_parents (const gchar * pathname, int mode)
95 if (pathname == NULL || *pathname == '\0') {
100 fn = g_strdup (pathname);
102 if (g_path_is_absolute (fn))
103 p = (gchar *) g_path_skip_root (fn);
108 while (*p && !G_IS_DIR_SEPARATOR (*p))
116 if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
117 if (g_mkdir (fn, mode) == -1) {
118 int errno_save = errno;
124 } else if (!g_file_test (fn, G_FILE_TEST_IS_DIR)) {
130 *p++ = G_DIR_SEPARATOR;
131 while (*p && G_IS_DIR_SEPARATOR (*p))
144 /* This version is copied from GLib 2.8.
145 * In GLib 2.6, it didn't check for a flag value being NULL, hence it
146 * hits an infinite loop in our flags serialize function
149 gst_flags_get_first_value (GFlagsClass * flags_class, guint value)
151 g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL);
153 if (flags_class->n_values) {
154 GFlagsValue *flags_value;
157 for (flags_value = flags_class->values; flags_value->value_name;
159 if (flags_value->value == 0)
162 for (flags_value = flags_class->values; flags_value->value_name;
164 if (flags_value->value != 0
165 && (flags_value->value & value) == flags_value->value)
173 /* Adapted from g_value_dup_object to use gst_object_ref */
174 #include "gstobject.h"
176 g_value_dup_gst_object (const GValue * value)
180 g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL);
182 o = value->data[0].v_pointer;
185 g_return_val_if_fail (GST_IS_OBJECT (o), NULL);
186 return gst_object_ref (o);