summaryrefslogtreecommitdiff
path: root/glnx-backports.h
blob: ad70ed901fd912a963f15c73d8fe3815a6910aa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 *
 * Copyright 1998 Manish Singh
 * Copyright 1998 Tim Janik
 * Copyright (C) 2015 Colin Walters <walters@verbum.org>
 * Copyright 2017 Emmanuele Bassi
 * SPDX-License-Identifier: LGPL-2.1-or-later
 * 
 * GLIB - Library of useful routines for C programming
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <string.h>

#include <gio/gio.h>

G_BEGIN_DECLS

#if !GLIB_CHECK_VERSION(2, 34, 0)
#define g_clear_pointer(pp, destroy) \
  G_STMT_START {                                                               \
    G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));                       \
    /* Only one access, please; work around type aliasing */                   \
    union { char *in; gpointer *out; } _pp;                                    \
    gpointer _p;                                                               \
    /* This assignment is needed to avoid a gcc warning */                     \
    GDestroyNotify _destroy = (GDestroyNotify) (destroy);                      \
                                                                               \
    _pp.in = (char *) (pp);                                                    \
    _p = *_pp.out;                                                             \
    if (_p)                                                                    \
      {                                                                        \
        *_pp.out = NULL;                                                       \
        _destroy (_p);                                                         \
      }                                                                        \
  } G_STMT_END
#endif

#if !GLIB_CHECK_VERSION(2, 40, 0)
#define g_info(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
#endif

#if !GLIB_CHECK_VERSION(2, 44, 0)

#define g_strv_contains glnx_strv_contains
gboolean              glnx_strv_contains  (const gchar * const *strv,
                                           const gchar         *str);

#define g_set_object(object_ptr, new_object) \
 (/* Check types match. */ \
  0 ? *(object_ptr) = (new_object), FALSE : \
  glnx_set_object ((GObject **) (object_ptr), (GObject *) (new_object)) \
 )
gboolean              glnx_set_object  (GObject **object_ptr,
                                        GObject  *new_object);

#endif /* !GLIB_CHECK_VERSION(2, 44, 0) */

#if !GLIB_CHECK_VERSION(2, 38, 0)
#define G_SPAWN_DEFAULT ((GSpawnFlags) 0)
#endif

#if !GLIB_CHECK_VERSION(2, 42, 0)
#define G_OPTION_FLAG_NONE ((GOptionFlags) 0)
#endif

#ifndef G_DBUS_METHOD_INVOCATION_HANDLED    /* added in 2.68 */
#define G_DBUS_METHOD_INVOCATION_HANDLED TRUE
#endif

#ifndef G_DBUS_METHOD_INVOCATION_UNHANDLED  /* added in 2.68 */
#define G_DBUS_METHOD_INVOCATION_UNHANDLED FALSE
#endif

#if !GLIB_CHECK_VERSION(2, 68, 0)
static inline gpointer _glnx_memdup2 (gconstpointer mem,
                                      gsize         byte_size) G_GNUC_ALLOC_SIZE(2);
static inline gpointer
_glnx_memdup2 (gconstpointer mem,
               gsize         byte_size)
{
  gpointer new_mem;

  if (mem && byte_size != 0)
    {
      new_mem = g_malloc (byte_size);
      memcpy (new_mem, mem, byte_size);
    }
  else
    new_mem = NULL;

  return new_mem;
}
#define g_memdup2 _glnx_memdup2
#endif

#ifndef G_OPTION_ENTRY_NULL   /* added in 2.70 */
#define G_OPTION_ENTRY_NULL { NULL, 0, 0, 0, NULL, NULL, NULL }
#endif

#ifndef G_APPROX_VALUE  /* added in 2.58 */
#define G_APPROX_VALUE(a, b, epsilon) \
  (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
#endif

#if !GLIB_CHECK_VERSION(2, 70, 0)
#define g_steal_fd _glnx_steal_fd
static inline int
_glnx_steal_fd (int *fdp)
{
  int fd = *fdp;
  *fdp = -1;
  return fd;
}
#endif

#if !GLIB_CHECK_VERSION(2, 74, 0)
#define G_APPLICATION_DEFAULT_FLAGS ((GApplicationFlags) 0)
#define G_CONNECT_DEFAULT ((GConnectFlags) 0)
#define G_IO_FLAG_NONE ((GIOFlags) 0)
#define G_MARKUP_DEFAULT_FLAGS ((GMarkupParseFlags) 0)
#define G_REGEX_DEFAULT ((GRegexCompileFlags) 0)
#define G_REGEX_MATCH_DEFAULT ((GRegexMatchFlags) 0)
#define G_TEST_SUBPROCESS_DEFAULT ((GTestSubprocessFlags) 0)
#define G_TEST_TRAP_DEFAULT ((GTestTrapFlags) 0)
#define G_TLS_CERTIFICATE_NO_FLAGS ((GTlsCertificateFlags) 0)
#define G_TYPE_FLAG_NONE ((GTypeFlags) 0)
#endif

G_END_DECLS