VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/nocrt-startup-common-win.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 22 months ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: nocrt-startup-common-win.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - No-CRT - Common Windows startup code.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "internal/nocrt.h"
42#include "internal/process.h"
43
44#include <iprt/nt/nt-and-windows.h>
45#ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
46# include <iprt/assert.h>
47#endif
48#include <iprt/getopt.h>
49#include <iprt/message.h>
50#include <iprt/path.h>
51#include <iprt/string.h>
52#include <iprt/utf16.h>
53
54#include "internal/compiler-vcc.h"
55
56
57/*********************************************************************************************************************************
58* Global Variables *
59*********************************************************************************************************************************/
60RT_C_DECLS_BEGIN
61DECL_HIDDEN_DATA(char) g_szrtProcExePath[RTPATH_MAX] = "Unknown.exe";
62DECL_HIDDEN_DATA(size_t) g_cchrtProcExePath = 11;
63DECL_HIDDEN_DATA(size_t) g_cchrtProcExeDir = 0;
64DECL_HIDDEN_DATA(size_t) g_offrtProcName = 0;
65RT_C_DECLS_END
66
67
68
69void rtVccWinInitProcExecPath(void)
70{
71 WCHAR wszPath[RTPATH_MAX];
72 UINT cwcPath = GetModuleFileNameW(NULL, wszPath, RT_ELEMENTS(wszPath));
73 if (cwcPath)
74 {
75 char *pszDst = g_szrtProcExePath;
76 int rc = RTUtf16ToUtf8Ex(wszPath, cwcPath, &pszDst, sizeof(g_szrtProcExePath), &g_cchrtProcExePath);
77 if (RT_SUCCESS(rc))
78 {
79 g_cchrtProcExeDir = g_offrtProcName = RTPathFilename(pszDst) - g_szrtProcExePath;
80 while ( g_cchrtProcExeDir >= 2
81 && RTPATH_IS_SLASH(g_szrtProcExePath[g_cchrtProcExeDir - 1])
82 && g_szrtProcExePath[g_cchrtProcExeDir - 2] != ':')
83 g_cchrtProcExeDir--;
84 }
85 else
86 {
87#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
88 RTMsgError("initProcExecPath: RTUtf16ToUtf8Ex failed: %Rrc\n", rc);
89#else
90 rtNoCrtFatalMsgWithRc(RT_STR_TUPLE("initProcExecPath: RTUtf16ToUtf8Ex failed: "), rc);
91#endif
92 }
93 }
94 else
95 {
96#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
97 RTMsgError("initProcExecPath: GetModuleFileNameW failed: %Rhrc\n", GetLastError());
98#else
99 rtNoCrtFatalWriteBegin(RT_STR_TUPLE("initProcExecPath: GetModuleFileNameW failed: "));
100 rtNoCrtFatalWriteWinRc(GetLastError());
101 rtNoCrtFatalWrite(RT_STR_TUPLE("\r\n"));
102#endif
103 }
104}
105
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use