mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-27 19:33:06 -04:00
Merge branch 'wip/smcv/memdup2' into 'master'
backports: Add a backport of g_memdup2() See merge request GNOME/libglnx!46
This commit is contained in:
16
LICENSES/LicenseRef-old-glib-tests.txt
Normal file
16
LICENSES/LicenseRef-old-glib-tests.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
This work is provided "as is"; redistribution and modification
|
||||
in whole or in part, in any medium, physical or electronic is
|
||||
permitted without restriction.
|
||||
|
||||
This work 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.
|
||||
|
||||
In no event shall the authors or contributors be liable for any
|
||||
direct, indirect, incidental, special, exemplary, or consequential
|
||||
damages (including, but not limited to, procurement of substitute
|
||||
goods or services; loss of use, data, or profits; or business
|
||||
interruption) however caused and on any theory of liability, whether
|
||||
in contract, strict liability, or tort (including negligence or
|
||||
otherwise) arising in any way out of the use of this software, even
|
||||
if advised of the possibility of such damage.
|
||||
@@ -1,8 +1,10 @@
|
||||
/* -*- 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.0-or-later
|
||||
* 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
|
||||
@@ -10,7 +12,7 @@
|
||||
* 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 of the License, or (at your option) any later version.
|
||||
* 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
|
||||
@@ -18,13 +20,13 @@
|
||||
* 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, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* 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
|
||||
@@ -85,6 +87,28 @@ gboolean glnx_set_object (GObject **object_ptr,
|
||||
#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
|
||||
|
||||
@@ -33,6 +33,7 @@ if get_option('tests')
|
||||
)
|
||||
|
||||
test_names = [
|
||||
'backports',
|
||||
'errors',
|
||||
'fdio',
|
||||
'macros',
|
||||
|
||||
36
tests/test-libglnx-backports.c
Normal file
36
tests/test-libglnx-backports.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
* Copyright 2019 Emmanuel Fleury
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later AND LicenseRef-old-glib-tests
|
||||
*/
|
||||
|
||||
#include "libglnx-config.h"
|
||||
#include "libglnx.h"
|
||||
|
||||
/* Testing g_memdup2() function with various positive and negative cases */
|
||||
static void
|
||||
test_memdup2 (void)
|
||||
{
|
||||
gchar *str_dup = NULL;
|
||||
const gchar *str = "The quick brown fox jumps over the lazy dog";
|
||||
|
||||
/* Testing negative cases */
|
||||
g_assert_null (g_memdup2 (NULL, 1024));
|
||||
g_assert_null (g_memdup2 (str, 0));
|
||||
g_assert_null (g_memdup2 (NULL, 0));
|
||||
|
||||
/* Testing normal usage cases */
|
||||
str_dup = g_memdup2 (str, strlen (str) + 1);
|
||||
g_assert_nonnull (str_dup);
|
||||
g_assert_cmpstr (str, ==, str_dup);
|
||||
|
||||
g_free (str_dup);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_add_func ("/strfuncs/memdup2", test_memdup2);
|
||||
return g_test_run();
|
||||
}
|
||||
Reference in New Issue
Block a user