From 63e9af5898e73b798d4ea313899cd3a4d89b9c4f Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 29 Apr 2021 22:25:47 +0200 Subject: [PATCH] Fixed the TinyGLib "functions in header" nonsense. --- src/include/tinyglib.h | 88 ++--------------------------- src/network/slirp/CMakeLists.txt | 2 +- src/network/slirp/tinyglib.c | 96 ++++++++++++++++++++++++++++++++ src/win/Makefile.mingw | 2 +- 4 files changed, 103 insertions(+), 85 deletions(-) create mode 100644 src/network/slirp/tinyglib.c diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h index 5f6c6a028..fc9b066ce 100644 --- a/src/include/tinyglib.h +++ b/src/include/tinyglib.h @@ -125,95 +125,17 @@ typedef struct _GRand { /* Functions */ #ifdef __GNUC__ -static gboolean g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, +extern gboolean g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup, gpointer user_data, GPid *child_pid, gint stdin_fd, gint stdout_fd, gint stderr_fd, GError **error) __attribute__((__unused__)); -static GString *g_string_new(gchar *base) __attribute__((__unused__)); -static gchar *g_string_free(GString *string, gboolean free_segment) __attribute__((__unused__)); -static gchar *g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) __attribute__((__unused__)); -static guint g_strv_length(gchar **str_array) __attribute__((__unused__)); +extern GString *g_string_new(gchar *base) __attribute__((__unused__)); +extern gchar *g_string_free(GString *string, gboolean free_segment) __attribute__((__unused__)); +extern gchar *g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) __attribute__((__unused__)); +extern guint g_strv_length(gchar **str_array) __attribute__((__unused__)); #endif -/* Must be a function, as libslirp redefines it as a macro. */ -static gboolean -g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error) -{ - return 0; -} - - -/* Needs bounds checking, but not really used by libslirp. */ -static GString * -g_string_new(gchar *base) -{ - char *ret = malloc(4096); - if (base) - strcpy(ret, base); - return ret; -} - - -/* Unimplemented, as with anything related to GString. */ -static gchar * -g_string_free(GString *string, gboolean free_segment) -{ - return (free_segment ? NULL : string); -} - - -/* Implementation borrowed from GLib itself. */ -static gchar * -g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) -{ - if (haystack_len < 0) - return strstr(haystack, needle); - else { - const gchar *p = haystack; - gsize needle_len = strlen(needle); - gsize haystack_len_unsigned = haystack_len; - const gchar *end; - gsize i; - - if (needle_len == 0) - return (gchar *) haystack; - - if (haystack_len_unsigned < needle_len) - return NULL; - - end = haystack + haystack_len - needle_len; - - while (p <= end && *p) { - for (i = 0; i < needle_len; i++) - if (p[i] != needle[i]) - goto next; - - return (gchar *)p; - -next: - p++; - } - - return NULL; - } -} - - -/* Implementation borrowed from GLib itself. */ -static guint -g_strv_length(gchar **str_array) -{ - guint i = 0; - while (str_array[i] != NULL) - ++i; - return i; -} - /* Macros */ diff --git a/src/network/slirp/CMakeLists.txt b/src/network/slirp/CMakeLists.txt index 83a8105ba..4393d9d55 100644 --- a/src/network/slirp/CMakeLists.txt +++ b/src/network/slirp/CMakeLists.txt @@ -13,7 +13,7 @@ # Copyright 2020,2021 David Hrdlička. # -add_library(slirp STATIC arp_table.c bootp.c cksum.c dnssearch.c if.c ip_icmp.c +add_library(slirp STATIC tinyglib.c arp_table.c bootp.c cksum.c dnssearch.c if.c ip_icmp.c ip_input.c ip_output.c mbuf.c misc.c sbuf.c slirp.c socket.c tcp_input.c tcp_output.c tcp_subr.c tcp_timer.c udp.c util.c version.c) diff --git a/src/network/slirp/tinyglib.c b/src/network/slirp/tinyglib.c new file mode 100644 index 000000000..d44658f52 --- /dev/null +++ b/src/network/slirp/tinyglib.c @@ -0,0 +1,96 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Minimal reimplementation of GLib for libslirp. + * + * + * + * Author: RichardG, + * + * Copyright 2020 RichardG. + */ +#include + + +/* Must be a function, as libslirp redefines it as a macro. */ +gboolean +g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, + gchar **envp, GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, GPid *child_pid, gint stdin_fd, + gint stdout_fd, gint stderr_fd, GError **error) +{ + return 0; +} + + +/* Needs bounds checking, but not really used by libslirp. */ +GString * +g_string_new(gchar *base) +{ + char *ret = malloc(4096); + if (base) + strcpy(ret, base); + return ret; +} + + +/* Unimplemented, as with anything related to GString. */ +gchar * +g_string_free(GString *string, gboolean free_segment) +{ + return (free_segment ? NULL : string); +} + + +/* Implementation borrowed from GLib itself. */ +gchar * +g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) +{ + if (haystack_len < 0) + return strstr(haystack, needle); + else { + const gchar *p = haystack; + gsize needle_len = strlen(needle); + gsize haystack_len_unsigned = haystack_len; + const gchar *end; + gsize i; + + if (needle_len == 0) + return (gchar *) haystack; + + if (haystack_len_unsigned < needle_len) + return NULL; + + end = haystack + haystack_len - needle_len; + + while (p <= end && *p) { + for (i = 0; i < needle_len; i++) + if (p[i] != needle[i]) + goto next; + + return (gchar *)p; + +next: + p++; + } + + return NULL; + } +} + + +/* Implementation borrowed from GLib itself. */ +guint +g_strv_length(gchar **str_array) +{ + guint i = 0; + while (str_array[i] != NULL) + ++i; + return i; +} diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index fc1e2bf39..4a52b2e08 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -698,7 +698,7 @@ SCSIOBJ := scsi.o scsi_device.o \ NETOBJ := network.o \ net_pcap.o \ - net_slirp.o \ + net_slirp.o tinyglib.o \ arp_table.o bootp.o cksum.o dnssearch.o if.o ip_icmp.o ip_input.o \ ip_output.o mbuf.o misc.o sbuf.o slirp.o socket.o tcp_input.o \ tcp_output.o tcp_subr.o tcp_timer.o udp.o util.o version.o \