gst/: Remove pre glib2.8 compatibility, fixes #340508
[platform/upstream/gstreamer.git] / gst / glib-compat.c
1 /*
2  * glib-compat.c
3  * Functions copied from glib 2.6 and 2.8
4  *
5  * Copyright 2005 David Schleef <ds@schleef.org>
6  */
7
8 /* gfileutils.c - File utility functions
9  *
10  *  Copyright 2000 Red Hat, Inc.
11  *
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.
16  *
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.
21  *
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.
26  */
27
28 #include "config.h"
29
30 #include <glib.h>
31 #include <glib/gstdio.h>
32
33 #include <stdio.h>
34 #include <errno.h>
35
36 #include "glib-compat.h"
37 #include "glib-compat-private.h"
38
39 #include <sys/stat.h>
40 #ifdef HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
43 #include <sys/types.h>
44 #if 0
45 #include <stdlib.h>
46 #include <stdarg.h>
47 #include <string.h>
48 #ifndef G_OS_WIN32
49 #include <sys/wait.h>
50 #endif
51 #include <fcntl.h>
52 #endif
53
54
55 #ifdef G_OS_WIN32
56 #include <windows.h>
57 #include <io.h>
58 #endif /* G_OS_WIN32 */
59
60
61 #ifdef 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 ";"
67 #else
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 ":"
73 #endif
74
75
76 /**
77  * gst_flags_get_first_value:
78  * @flags_class: a #GFlagsClass
79  * @value: the value
80  *
81  * Returns the first GFlagsValue which is set in value.
82  *
83  * This version is copied from GLib 2.8.
84  * In GLib 2.6, it didn't check for a flag value being NULL, hence it
85  * hits an infinite loop in our flags serialize function
86  *
87  * Returns: the first GFlagsValue which is set in value, or NULL if none is set.
88  */
89 GFlagsValue *
90 gst_flags_get_first_value (GFlagsClass * flags_class, guint value)
91 {
92   g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL);
93
94   if (flags_class->n_values) {
95     GFlagsValue *flags_value;
96
97     if (value == 0) {
98       for (flags_value = flags_class->values; flags_value->value_name;
99           flags_value++)
100         if (flags_value->value == 0)
101           return flags_value;
102     } else {
103       for (flags_value = flags_class->values; flags_value->value_name;
104           flags_value++)
105         if (flags_value->value != 0
106             && (flags_value->value & value) == flags_value->value)
107           return flags_value;
108     }
109   }
110
111   return NULL;
112 }
113
114 /* Adapted from g_value_dup_object to use gst_object_ref */
115 #include "gstobject.h"
116 /**
117  * g_value_dup_gst_object:
118  * @value: the #GstObject value to dup
119  *
120  * Get the contents of a G_TYPE_OBJECT derived GValue, increasing its reference count.
121  * This function exists because of unsafe reference counting in old glib versions.
122  *
123  * Returns: object content of value, should be unreferenced with gst_object_unref()
124  * when no longer needed.
125  */
126 GObject *
127 g_value_dup_gst_object (const GValue * value)
128 {
129   GObject *o;
130
131   g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL);
132
133   o = value->data[0].v_pointer;
134   if (!o)
135     return NULL;
136   g_return_val_if_fail (GST_IS_OBJECT (o), NULL);
137   return gst_object_ref (o);
138 }