summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx44
1 files changed, 12 insertions, 32 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index 7e295fb37..97a31cdab 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -68,7 +68,7 @@ extern "C" {
}
/*
- Convert a UTF-8 string to Windows wide character encoding (UTF-16).
+ Convert UTF-8 string to Windows wide character encoding (UTF-16).
This helper function is used throughout this file to convert UTF-8
strings to Windows specific UTF-16 encoding for filenames, paths, or
@@ -86,15 +86,14 @@ extern "C" {
'wbuf' is NULL a new buffer is allocated with realloc(). Hence the pointer
'wbuf' can be shared among multiple calls to this function if it has been
initialized with NULL (or malloc or realloc) before the first call.
- Ideally every call to this function has its own static pointer though.
The return value is either the old value of 'wbuf' (if the string fits)
- or a pointer at the (re)allocated buffer.
+ or a pointer to the (re)allocated buffer.
Pseudo doxygen docs (static function intentionally not documented):
param[in] utf8 input string (UTF-8)
- param[in,out] wbuf in: pointer to output string buffer
+ param[in,out] wbuf in: pointer to output string buffer or NULL
out: new string (the pointer may be changed)
param[in] lg optional: input string length (default = -1)
@@ -227,43 +226,24 @@ FILE *Fl_WinAPI_System_Driver::fopen(const char *fnam, const char *mode) {
}
int Fl_WinAPI_System_Driver::system(const char *cmd) {
-# ifdef __MINGW32__
- return ::system(fl_utf2mbcs(cmd));
-# else
return _wsystem(utf8_to_wchar(cmd, wbuf));
-# endif
}
int Fl_WinAPI_System_Driver::execvp(const char *file, char *const *argv) {
-# ifdef __MINGW32__
- return _execvp(fl_utf2mbcs(file), argv);
-# else
- wchar_t **ar;
+ int n = 0;
+ while (argv[n]) n++; // count args
+ wchar_t **ar = (wchar_t **)calloc(sizeof(wchar_t *), n + 1);
+ // convert arguments first; trailing NULL provided by calloc()
+ for (int i = 0; i < n; i++)
+ ar[i] = utf8_to_wchar(argv[i], ar[i]); // alloc and assign
+ // convert executable file and execute it ...
utf8_to_wchar(file, wbuf);
-
- int i = 0, n = 0;
- while (argv[i]) {i++; n++;}
- ar = (wchar_t **)malloc(sizeof(wchar_t *) * (n + 1));
- i = 0;
- while (i <= n) {
- unsigned wn;
- unsigned len = (unsigned)strlen(argv[i]);
- wn = fl_utf8toUtf16(argv[i], len, NULL, 0) + 1; // Query length
- ar[i] = (wchar_t *)malloc(sizeof(wchar_t) * wn);
- wn = fl_utf8toUtf16(argv[i], len, (unsigned short *)ar[i], wn); // Convert string
- ar[i][wn] = 0;
- i++;
- }
- ar[n] = NULL;
_wexecvp(wbuf, ar); // STR #3040
- i = 0;
- while (i < n) {
+ // clean up (reached only if _wexecvp() failed)
+ for (int i = 0; i < n; i++)
free(ar[i]);
- i++;
- }
free(ar);
return -1; // STR #3040
-#endif
}
int Fl_WinAPI_System_Driver::chmod(const char *fnam, int mode) {