utils: import ptr array lookup with GEqualFunc from GLib 2.54

This fixes the build when using GLib < 2.54.
This commit is contained in:
Aleksander Morgado
2021-03-01 15:55:22 +01:00
parent e1372a716e
commit a9611c6279
5 changed files with 64 additions and 1 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ ModemManager_SOURCES = \
main.c \
mm-context.h \
mm-context.c \
mm-utils.h \
mm-utils.h mm-utils.c \
mm-private-boxed-types.h \
mm-private-boxed-types.c \
mm-auth-provider.h \
@@ -27,6 +27,7 @@
#include "mm-kernel-device-generic.h"
#include "mm-kernel-device-generic-rules.h"
#include "mm-log-object.h"
#include "mm-utils.h"
#if !defined UDEVRULESDIR
# error UDEVRULESDIR is not defined
+1
View File
@@ -28,6 +28,7 @@
#include "mm-plugin-manager.h"
#include "mm-plugin.h"
#include "mm-shared.h"
#include "mm-utils.h"
#include "mm-log-object.h"
#define SHARED_PREFIX "libmm-shared"
+47
View File
@@ -0,0 +1,47 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details:
*
* Singleton support imported from NetworkManager.
* (C) Copyright 2014 Red Hat, Inc.
*
* GPtrArray lookup with GEqualFunc imported from GLib 2.48
*/
#include "mm-utils.h"
#if !GLIB_CHECK_VERSION(2,54,0)
gboolean
mm_ptr_array_find_with_equal_func (GPtrArray *haystack,
gconstpointer needle,
GEqualFunc equal_func,
guint *index_)
{
guint i;
g_return_val_if_fail (haystack != NULL, FALSE);
if (equal_func == NULL)
equal_func = g_direct_equal;
for (i = 0; i < haystack->len; i++) {
if (equal_func (g_ptr_array_index (haystack, i), needle)) {
if (index_ != NULL)
*index_ = i;
return TRUE;
}
}
return FALSE;
}
#endif
+14
View File
@@ -12,6 +12,8 @@
*
* Singleton support imported from NetworkManager.
* (C) Copyright 2014 Red Hat, Inc.
*
* GPtrArray lookup with GEqualFunc imported from GLib 2.48
*/
#ifndef MM_UTILS_H
@@ -78,4 +80,16 @@
} \
MM_DEFINE_SINGLETON_DESTRUCTOR(TYPE)
#if !GLIB_CHECK_VERSION(2,54,0)
/* Pointer Array lookup with a GEqualFunc, imported from GLib 2.54 */
#define g_ptr_array_find_with_equal_func mm_ptr_array_find_with_equal_func
gboolean mm_ptr_array_find_with_equal_func (GPtrArray *haystack,
gconstpointer needle,
GEqualFunc equal_func,
guint *index_);
#endif
#endif /* MM_UTILS_H */