From e9596a4b3d5f002df7e279d59592311ba527ef51 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 4 Mar 2025 23:30:53 +0100 Subject: [PATCH 1/5] Add compatibility setenv() implementation Some systems like IRIX don't provide an implementation of setenv(), only putenv(). To support those cases, we first check at configure time if the setenv() function is available, otherwise we provide our own. See: https://github.com/dillo-browser/dillo/issues/363 --- configure.ac | 7 +++++++ dlib/Makefile.am | 4 +++- dlib/compat.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ dlib/compat.h | 31 +++++++++++++++++++++++++++++++ dpi/downloads.cc | 3 ++- src/menu.cc | 4 +++- 6 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 dlib/compat.c create mode 100644 dlib/compat.h diff --git a/configure.ac b/configure.ac index fd5c8faa2..280779f43 100644 --- a/configure.ac +++ b/configure.ac @@ -679,6 +679,13 @@ dnl ----------------------- dnl AC_CHECK_HEADERS(fcntl.h unistd.h sys/uio.h) +dnl -------------------- +dnl Checks for functions +dnl -------------------- +dnl +AC_CHECK_DECLS([setenv], [], [], [[#include ]]) +AC_CHECK_FUNCS([setenv], [], []) + dnl -------------------------- dnl Check for compiler options dnl -------------------------- diff --git a/dlib/Makefile.am b/dlib/Makefile.am index 0d44c139b..796c6492c 100644 --- a/dlib/Makefile.am +++ b/dlib/Makefile.am @@ -5,4 +5,6 @@ noinst_LIBRARIES = libDlib.a libDlib_a_SOURCES = \ dlib.h \ - dlib.c + dlib.c \ + compat.h \ + compat.c diff --git a/dlib/compat.c b/dlib/compat.c new file mode 100644 index 000000000..66bc84668 --- /dev/null +++ b/dlib/compat.c @@ -0,0 +1,47 @@ +/* + * File: compat.c + * + * Copyright (C) 2025 Rodrigo Arias Mallo + * + * 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 3 of the License, or + * (at your option) any later version. + */ + +#define _DEFAULT_SOURCE /* Needed to load putenv on glibc */ + +#include "compat.h" + +#include /* errno */ +#include /* putenv */ +#include /* strlen */ + +#if !HAVE_SETENV +int setenv(const char *name, const char *val, int overwrite) +{ + if (name == NULL || name[0] == '\0' || strchr(name, '=') == NULL || val == NULL) { + errno = EINVAL; + return -1; + } + + /* Don't do anything if already defined with overwrite unset */ + if (overwrite == 0 && getenv(name) != NULL) + return 0; + + /* Otherwise undefine first */ + unsetenv(name); + + int len = strlen(name) + strlen(val) + 2; + char *env = malloc(len); + + if (env == NULL) + return -1; + + strcpy(env, name); + strcat(env, "="); + strcat(env, val); + + return putenv(env); +} +#endif diff --git a/dlib/compat.h b/dlib/compat.h new file mode 100644 index 000000000..82081c808 --- /dev/null +++ b/dlib/compat.h @@ -0,0 +1,31 @@ +/* + * File: compat.h + * + * Copyright (C) 2025 Rodrigo Arias Mallo + * + * 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 3 of the License, or + * (at your option) any later version. + */ + +#ifndef COMPAT_H +#define COMPAT_H + +#include "config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !HAVE_DECL_SETENV +int setenv(const char *name, const char *val, int overwrite); +#endif + +//# include /* for setenv */ + +#ifdef __cplusplus +} +#endif + +#endif /* COMPAT_H */ diff --git a/dpi/downloads.cc b/dpi/downloads.cc index 69e04f8ff..16930dae5 100644 --- a/dpi/downloads.cc +++ b/dpi/downloads.cc @@ -2,7 +2,7 @@ * File: downloads.cc * * Copyright (C) 2005-2007 Jorge Arellano Cid - * Copyright (C) 2024 Rodrigo Arias Mallo + * Copyright (C) 2024-2025 Rodrigo Arias Mallo * * 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 @@ -45,6 +45,7 @@ #include "config.h" #include "dpiutil.h" #include "../dpip/dpip.h" +#include "dlib/compat.h" /* setenv */ /* * Debugging macros diff --git a/src/menu.cc b/src/menu.cc index 3cdc2f778..9dbbcc952 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -2,7 +2,7 @@ * File: menu.cc * * Copyright (C) 2005-2007 Jorge Arellano Cid - * Copyright (C) 2024 Rodrigo Arias Mallo + * Copyright (C) 2024-2025 Rodrigo Arias Mallo * * 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 @@ -30,6 +30,8 @@ #include "ui.hh" // for (UI *) #include "keys.hh" #include "timeout.hh" +#include +#include "dlib/compat.h" /* setenv */ /* * Local data types From 18cd05959211046d8f461a4bbbe40d8690205c06 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 5 Mar 2025 21:00:01 +0100 Subject: [PATCH 2/5] Manually define TCP_NODELAY in IRIX IRIX systems seems to fail to include the netinet/tcp.h header, so as we only require TCP_NODELAY we can simply define it. See: https://github.com/dillo-browser/dillo/issues/363 --- dpid/dpid.c | 7 ++++++- src/IO/dpi.c | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dpid/dpid.c b/dpid/dpid.c index 49ee4dc85..38e19b61c 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -27,7 +27,12 @@ #include #include #include -#include +#ifdef __sgi +/* IRIX fails to include netinet/tcp.h */ +# define TCP_NODELAY 1 +#else +# include +#endif #include #include diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 2d265b781..e93ec685b 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -2,6 +2,7 @@ * File: dpi.c * * Copyright (C) 2002-2007 Jorge Arellano Cid + * Copyright (C) 2025 Rodrigo Arias Mallo * * 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 @@ -31,7 +32,12 @@ #include #include #include -#include +#ifdef __sgi +/* IRIX fails to include netinet/tcp.h */ +# define TCP_NODELAY 1 +#else +# include +#endif #include #include From 05807be4f32d0978c360395ddbf75b3dfd188bec Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 5 Mar 2025 23:36:44 +0100 Subject: [PATCH 3/5] Avoid unsetenv() on IRIX as it is not supported --- dlib/compat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlib/compat.c b/dlib/compat.c index 66bc84668..17f4cb7f6 100644 --- a/dlib/compat.c +++ b/dlib/compat.c @@ -29,8 +29,10 @@ int setenv(const char *name, const char *val, int overwrite) if (overwrite == 0 && getenv(name) != NULL) return 0; +#ifndef __sgi /* Not available on IRIX */ /* Otherwise undefine first */ unsetenv(name); +#endif int len = strlen(name) + strlen(val) + 2; char *env = malloc(len); From c406b06b61b07451ba5fb4aa591f7088113385d1 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 5 Mar 2025 23:43:09 +0100 Subject: [PATCH 4/5] Fix strchr condition in compat setenv() --- dlib/compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlib/compat.c b/dlib/compat.c index 17f4cb7f6..de8973dc9 100644 --- a/dlib/compat.c +++ b/dlib/compat.c @@ -20,7 +20,7 @@ #if !HAVE_SETENV int setenv(const char *name, const char *val, int overwrite) { - if (name == NULL || name[0] == '\0' || strchr(name, '=') == NULL || val == NULL) { + if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL || val == NULL) { errno = EINVAL; return -1; } From 72603e6a4f05d2e7f76a795e51e837e48b1fd75d Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 6 Mar 2025 19:17:29 +0100 Subject: [PATCH 5/5] Add missing headers for select() in IRIX Older standards require extra headers to define all types when using select(). See: https://github.com/dillo-browser/dillo/issues/363 --- dpid/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpid/main.c b/dpid/main.c index 90432be50..e6bc46dbb 100644 --- a/dpid/main.c +++ b/dpid/main.c @@ -23,6 +23,9 @@ #include /* for exit */ #include /* for assert */ #include /* for umask */ +#include /* for select */ +#include /* for struct timeval */ +#include /* for fd_set */ #include "dpid_common.h" #include "dpid.h"