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..de8973dc9 --- /dev/null +++ b/dlib/compat.c @@ -0,0 +1,49 @@ +/* + * 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; + +#ifndef __sgi /* Not available on IRIX */ + /* Otherwise undefine first */ + unsetenv(name); +#endif + + 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/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/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" 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 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