summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-02-10 11:55:34 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2020-02-10 12:10:40 +0100
commit4c1b92eb52db567b4c1618222bb3007a2a2e7d9b (patch)
tree58081f8e02a8d43dc273de033d454c16e9946f28 /src/drivers/WinAPI
parentdcb848ca3ed0ebddd4f28888d2a8ab2f59c9fd1c (diff)
Implement fl_putenv() as cross-platform putenv()
Diffstat (limited to 'src/drivers/WinAPI')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H10
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx19
2 files changed, 20 insertions, 9 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index b4189da4a..d4b12fc34 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -1,19 +1,19 @@
//
// "$Id$"
//
-// Definition of Windows system driver for the Fast Light Tool Kit (FLTK).
+// Windows system driver for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2018 by Bill Spitzak and others.
+// Copyright 2010-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/str.php
//
/**
@@ -46,7 +46,7 @@ public:
virtual void fatal(const char *format, va_list args);
virtual char *utf2mbcs(const char *s);
virtual char *getenv(const char *var);
- virtual int putenv(char *var) {return _putenv(var);} // *FIXME* needs string conversion
+ virtual int putenv(const char *var);
virtual int open(const char *fnam, int oflags, int pmode);
virtual int open_ext(const char *fnam, int binary, int oflags, int pmode);
virtual FILE *fopen(const char *fnam, const char *mode);
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index b18b9c98e..10c6a7b38 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -1,19 +1,19 @@
//
// "$Id$"
//
-// Definition of Apple Darwin system driver.
+// Definition of Windows system driver for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2018 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/str.php
//
#include "../../config_lib.h"
@@ -196,6 +196,17 @@ char *Fl_WinAPI_System_Driver::getenv(const char *var) {
return wchar_to_utf8(ret, buf);
}
+int Fl_WinAPI_System_Driver::putenv(const char *var) {
+ unsigned len = (unsigned)strlen(var);
+ unsigned wn = fl_utf8toUtf16(var, len, NULL, 0) + 1; // Query length
+ wchar_t *wbuf = (wchar_t *)malloc(sizeof(wchar_t) * wn);
+ wn = fl_utf8toUtf16(var, len, (unsigned short *)wbuf, wn);
+ wbuf[wn] = 0;
+ int ret = _wputenv(wbuf);
+ free(wbuf);
+ return ret;
+}
+
int Fl_WinAPI_System_Driver::open(const char *fnam, int oflags, int pmode) {
utf8_to_wchar(fnam, wbuf);
if (pmode == -1) return _wopen(wbuf, oflags);