Fix message references for inches and feet
[survex.git] / src / wrapaven.c
blob447b9b3f6f2dc68b0171a425c91652dd33931942
1 /* wrapaven.c
2 * Set OPENSSL_MODULES to .exe's directory and run real .exe
4 * Copyright (C) 2002,2010,2014,2024 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <stdlib.h>
22 #include <string.h>
23 #include <windows.h>
25 int APIENTRY
26 wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmdShow)
28 DWORD len = 256;
29 wchar_t *buf = NULL;
30 (void)hInst; /* suppress compiler warning */
31 (void)hPrevInst; /* suppress compiler warning */
32 while (1) {
33 DWORD got;
34 buf = realloc(buf, len * sizeof(wchar_t));
35 if (!buf) return 1;
36 got = GetModuleFileNameW(NULL, buf, len);
37 if (got < len) {
38 /* Strange Microsoft nastiness - skip prefix "\\?\" if present. */
39 if (wcsncmp(buf, L"\\\\?\\", 4) == 0) {
40 buf += 4;
41 got -= 4;
43 wchar_t *p = wcsrchr(buf, L'\\');
44 wchar_t *e_val = buf;
45 size_t e_len;
46 if (p) {
47 e_len = p - buf;
48 } else {
49 e_val = L".";
50 e_len = 1;
52 wchar_t *e = malloc((e_len + strlen("OPENSSL_MODULES=") + 1) * sizeof(wchar_t));
53 if (!e) return 1;
54 wcscpy(e, L"OPENSSL_MODULES=");
55 memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len * sizeof(wchar_t));
56 e[strlen("OPENSSL_MODULES=") + e_len] = L'\0';
57 _wputenv(e);
58 buf[got - 5] = L'_';
59 break;
61 len += len;
63 /* ShellExecute returns an HINSTANCE for some strange reason - the docs say
64 * the only valid operation is to convert it to "INT_PTR" (which seems to
65 * actually be an integer type. Marvellous. */
66 if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, lpCmdLine, NULL, nCmdShow) <= 32) {
67 return 1;
69 return 0;