Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdlib.h>]])
AC_CHECK_FUNCS([setenv], [], [])

dnl --------------------------
dnl Check for compiler options
dnl --------------------------
Expand Down
4 changes: 3 additions & 1 deletion dlib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ noinst_LIBRARIES = libDlib.a

libDlib_a_SOURCES = \
dlib.h \
dlib.c
dlib.c \
compat.h \
compat.c
49 changes: 49 additions & 0 deletions dlib/compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* File: compat.c
*
* Copyright (C) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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.h> /* errno */
#include <stdlib.h> /* putenv */
#include <string.h> /* 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
31 changes: 31 additions & 0 deletions dlib/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* File: compat.h
*
* Copyright (C) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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 <stdlib.h> /* for setenv */

#ifdef __cplusplus
}
#endif

#endif /* COMPAT_H */
3 changes: 2 additions & 1 deletion dpi/downloads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* File: downloads.cc
*
* Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
* Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
* Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
Expand Down Expand Up @@ -45,6 +45,7 @@
#include "config.h"
#include "dpiutil.h"
#include "../dpip/dpip.h"
#include "dlib/compat.h" /* setenv */

/*
* Debugging macros
Expand Down
7 changes: 6 additions & 1 deletion dpid/dpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifdef __sgi
/* IRIX fails to include netinet/tcp.h */
# define TCP_NODELAY 1
#else
# include <netinet/tcp.h>
#endif
#include <arpa/inet.h>

#include <unistd.h>
Expand Down
3 changes: 3 additions & 0 deletions dpid/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <stdlib.h> /* for exit */
#include <assert.h> /* for assert */
#include <sys/stat.h> /* for umask */
#include <sys/select.h> /* for select */
#include <sys/time.h> /* for struct timeval */
#include <sys/types.h> /* for fd_set */

#include "dpid_common.h"
#include "dpid.h"
Expand Down
8 changes: 7 additions & 1 deletion src/IO/dpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* File: dpi.c
*
* Copyright (C) 2002-2007 Jorge Arellano Cid <jcid@dillo.org>
* Copyright (C) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
Expand Down Expand Up @@ -31,7 +32,12 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifdef __sgi
/* IRIX fails to include netinet/tcp.h */
# define TCP_NODELAY 1
#else
# include <netinet/tcp.h>
#endif
#include <arpa/inet.h>
#include <netdb.h>

Expand Down
4 changes: 3 additions & 1 deletion src/menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* File: menu.cc
*
* Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
* Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
* Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
Expand Down Expand Up @@ -30,6 +30,8 @@
#include "ui.hh" // for (UI *)
#include "keys.hh"
#include "timeout.hh"
#include <stdlib.h>
#include "dlib/compat.h" /* setenv */

/*
* Local data types
Expand Down
Loading