feature list: Workaround g_string_replace on GLib < 2.68

g_string_replace was added in GLib 2.68. We only expect to find a
string once and erase it instead of replacing it, so a workaround
is simple.

Remove the similar workaround in capture-pcap-util-unix.c for
libpcap.
This commit is contained in:
John Thacker 2024-11-21 17:29:20 -05:00
parent f70ead9865
commit 8f651e222e
2 changed files with 20 additions and 11 deletions

View File

@ -163,16 +163,7 @@ gather_caplibs_compile_info(feature_list l)
void
gather_caplibs_runtime_info(feature_list l)
{
const char *vstr = pcap_lib_version();
/*
* Remove the substring "version" from the output of pcap_lib_version()
* to be consistent with our format.
*/
if (g_str_has_prefix(vstr, "libpcap version ")) /* Sanity check */
with_feature(l, "libpcap %s", vstr + strlen("libpcap version "));
else
with_feature(l, "%s", vstr);
with_feature(l, "%s", pcap_lib_version());
}
#else /* HAVE_LIBPCAP */

View File

@ -14,6 +14,19 @@
#include <wsutil/feature_list.h>
#if !GLIB_CHECK_VERSION(2, 68, 0)
static GString*
g_string_find_and_erase(GString *string, const char* find)
{
/* Find and erases find a single time. */
const char* pos = strstr(string->str, find);
if (pos != NULL) {
g_string_erase(string, pos - string->str, strlen(find));
}
return string;
}
#endif
void
with_feature(feature_list l, const char *fmt, ...)
{
@ -22,9 +35,14 @@ with_feature(feature_list l, const char *fmt, ...)
va_start(arg, fmt);
g_string_append_vprintf(msg, fmt, arg);
va_end(arg);
/* Strip "version from the string" */
/* Strip "version" from the string */
#if GLIB_CHECK_VERSION(2, 68, 0)
g_string_replace(msg, " version", "", 0);
g_string_replace(msg, " based on", "", 0);
#else
g_string_find_and_erase(msg, " version");
g_string_find_and_erase(msg, " based on");
#endif
*l = g_list_prepend(*l, g_string_free(msg, FALSE));
}