|
|
commit d3a3ab40b7cfe3aa5adbcbc7895ec48d39dc89c1
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Mon Mar 18 22:29:50 2024 +0100
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Mon Mar 18 22:29:50 2024 +0100
Replace setenv() with putenv() on old systems (+937)
Add system check for setenv() function in configure and CMake.
CMake/resources.cmake | 2 ++
configh.cmake.in | 8 ++++++++
configh.in | 8 ++++++++
configure.ac | 3 +++
src/drivers/X11/Fl_X11_Screen_Driver.cxx | 23 ++++++++++++++++++++---
5 files changed, 41 insertions(+), 3 deletions(-)
diff --git CMake/resources.cmake CMake/resources.cmake
index 50d630d..4cc2d3b 100644
--- CMake/resources.cmake
+++ CMake/resources.cmake
@@ -204,6 +204,8 @@ CHECK_FUNCTION_EXISTS (strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS (strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS (vsnprintf HAVE_VSNPRINTF)
+check_function_exists(setenv HAVE_SETENV)
+
if(HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX)
set(MSG "POSIX compatible scandir")
message(STATUS "Looking for ${MSG}")
diff --git configh.cmake.in configh.cmake.in
index 0dc1b9f..982e9f8 100644
--- configh.cmake.in
+++ configh.cmake.in
@@ -241,6 +241,14 @@
#cmakedefine01 USE_POLL
/*
+ * HAVE_SETENV:
+ *
+ * Whether or not POSIX setenv() is available from stdlib.h.
+ */
+
+#cmakedefine01 HAVE_SETENV
+
+/*
* Do we have various image libraries?
*/
diff --git configh.in configh.in
index 54ade6c..54ddf96 100644
--- configh.in
+++ configh.in
@@ -240,6 +240,14 @@
#define USE_POLL 0
/*
+ * HAVE_SETENV:
+ *
+ * Whether or not POSIX setenv() is available from stdlib.h.
+ */
+
+#define HAVE_SETENV 0
+
+/*
* Do we have various image libraries?
*/
diff --git configure.ac configure.ac
index 6b64110..e519f84 100644
--- configure.ac
+++ configure.ac
@@ -620,6 +620,9 @@ AC_CHECK_FUNCS([strcasecmp strlcat strlcpy])
AC_CHECK_HEADERS([locale.h])
AC_CHECK_FUNCS([localeconv])
+dnl HP-UX 11.11 does not provide setenv()
+AC_CHECK_FUNCS([setenv])
+
dnl FLTK library uses math library functions...
AC_SEARCH_LIBS([pow], [m])
diff --git src/drivers/X11/Fl_X11_Screen_Driver.cxx src/drivers/X11/Fl_X11_Screen_Driver.cxx
index 7987536..8dc79fc 100644
--- src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -75,9 +75,26 @@ Fl_X11_Screen_Driver::Fl_X11_Screen_Driver() : Fl_Unix_Screen_Driver() {
key_table_size = 0;
}
-void Fl_X11_Screen_Driver::display(const char *d)
-{
- if (d) setenv("DISPLAY", d, 1);
+void Fl_X11_Screen_Driver::display(const char *d) {
+ if (!d) return;
+ // Issue #937:
+ // setenv() is available since POSIX.1-2001
+ // https://pubs.opengroup.org/onlinepubs/009604499/functions/setenv.html
+#if HAVE_SETENV
+ setenv("DISPLAY", d, 1);
+#else // HAVE_SETENV
+ // Use putenv() for old systems (similar to FLTK 1.3)
+ static char e[1024];
+ strcpy(e, "DISPLAY=");
+ strlcat(e, d, sizeof(e));
+ for (char *c = e + 8; *c != ':'; c++) {
+ if (!*c) {
+ strlcat(e,":0.0",sizeof(e));
+ break;
+ }
+ }
+ putenv(e);
+#endif // HAVE_SETENV
}
void fl_x11_use_display(Display *d) {
[ Direct Link to Message ] | |
|
| |