Fixed the TinyGLib "functions in header" nonsense.

This commit is contained in:
OBattler
2021-04-29 22:25:47 +02:00
parent fbe2537ddd
commit 63e9af5898
4 changed files with 103 additions and 85 deletions

View File

@@ -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 */

View File

@@ -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)

View File

@@ -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, <richardg867@gmail.com>
*
* Copyright 2020 RichardG.
*/
#include <tinyglib.h>
/* 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;
}

View File

@@ -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 \