-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable GDAL for Microsoft Windows build
- Loading branch information
Showing
6 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* wrapaven.c | ||
* Set OPENSSL_MODULES to .exe's directory and run real .exe | ||
* | ||
* Copyright (C) 2002,2010,2014,2024 Olly Betts | ||
* | ||
* 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <windows.h> | ||
|
||
int APIENTRY | ||
wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmdShow) | ||
{ | ||
DWORD len = 256; | ||
wchar_t *buf = NULL; | ||
(void)hInst; /* suppress compiler warning */ | ||
(void)hPrevInst; /* suppress compiler warning */ | ||
while (1) { | ||
DWORD got; | ||
buf = realloc(buf, len * sizeof(wchar_t)); | ||
if (!buf) return 1; | ||
got = GetModuleFileNameW(NULL, buf, len); | ||
if (got < len) { | ||
/* Strange Microsoft nastiness - skip prefix "\\?\" if present. */ | ||
if (wcsncmp(buf, L"\\\\?\\", 4) == 0) { | ||
buf += 4; | ||
got -= 4; | ||
} | ||
wchar_t *p = wcsrchr(buf, L'\\'); | ||
wchar_t *e_val = buf; | ||
size_t e_len; | ||
if (p) { | ||
e_len = p - buf; | ||
} else { | ||
e_val = L"."; | ||
e_len = 1; | ||
} | ||
wchar_t *e = malloc((e_len + strlen("OPENSSL_MODULES=") + 1) * sizeof(wchar_t)); | ||
if (!e) return 1; | ||
wcscpy(e, L"OPENSSL_MODULES="); | ||
memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len * sizeof(wchar_t)); | ||
e[strlen("OPENSSL_MODULES=") + e_len] = L'\0'; | ||
_wputenv(e); | ||
buf[got - 5] = L'_'; | ||
break; | ||
} | ||
len += len; | ||
} | ||
/* ShellExecute returns an HINSTANCE for some strange reason - the docs say | ||
* the only valid operation is to convert it to "INT_PTR" (which seems to | ||
* actually be an integer type. Marvellous. */ | ||
if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, lpCmdLine, NULL, nCmdShow) <= 32) { | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* wrapsurvexport.c | ||
* Set OPENSSL_MODULES to .exe's directory and run real .exe | ||
* | ||
* Copyright (C) 2002,2010,2014,2024 Olly Betts | ||
* | ||
* 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <process.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
const char *p = strrchr(argv[0], '\\'); | ||
const char *e_val = argv[0]; | ||
size_t e_len; | ||
size_t a_len; | ||
(void)argc; | ||
if (p) { | ||
e_len = p - argv[0]; | ||
a_len = e_len + 1; | ||
} else { | ||
e_val = "."; | ||
e_len = 1; | ||
a_len = 0; | ||
} | ||
char *e = malloc(e_len + strlen("OPENSSL_MODULES=") + 1); | ||
if (!e) return 1; | ||
strcpy(e, "OPENSSL_MODULES="); | ||
memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len); | ||
e[strlen("OPENSSL_MODULES=") + e_len] = '\0'; | ||
putenv(e); | ||
char *a = malloc(a_len + strlen("survexpor_.exe") + 1); | ||
if (!a) return 1; | ||
memcpy(a, argv[0], a_len); | ||
strcpy(a + a_len, "survexpor_.exe"); | ||
const char *real_argv0 = argv[0]; | ||
// Behind the scenes it appears Microsoft's _execv() actually takes the | ||
// argv passed and crudely glues it together into a command line string | ||
// with spaces in between but *WITHOUT ANY ESCAPING*, and then it gets | ||
// split back up into arguments at spaces, so an argument containing a | ||
// space gets split into two arguments. Coupled with the default | ||
// installation directory path containing a space (C:\Program Files) this | ||
// doesn't work out well. Words fail me. | ||
// | ||
// Apparently putting quotes around the argument is necessary. | ||
for (int i = 0; i < argc; ++i) { | ||
const char *arg = argv[i]; | ||
if (arg[strcspn(arg, " \t\n\r\v")]) { | ||
// Argument contains whitespace. | ||
char *newarg = malloc(strlen(arg) + 3); | ||
if (!newarg) return 1; | ||
newarg[0] = '"'; | ||
strcpy(newarg + 1, arg); | ||
strcat(newarg + 1, "\""); | ||
argv[i] = newarg; | ||
} | ||
} | ||
_execv(a, (const char * const*)argv); | ||
printf("%s: %s\n", real_argv0, strerror(errno)); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters