1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: extendloaderenvironment.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_DESKTOP_WIN32_SOURCE_EXTENDLOADERENVIRONMENT_HXX
32 #define INCLUDED_DESKTOP_WIN32_SOURCE_EXTENDLOADERENVIRONMENT_HXX
34 #include "sal/config.h"
40 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
41 #define MY_STRING(s) (s), MY_LENGTH(s)
43 namespace desktop_win32
{
45 inline WCHAR
* commandLineAppend(
46 WCHAR
* buffer
, WCHAR
const * text
, std::size_t length
)
48 wcsncpy(buffer
, text
, length
+ 1); // trailing null
49 return buffer
+ length
;
52 inline WCHAR
* commandLineAppend(WCHAR
* buffer
, WCHAR
const * text
) {
53 return commandLineAppend(buffer
, text
, wcslen(text
));
56 inline WCHAR
* commandLineAppendEncoded(WCHAR
* buffer
, WCHAR
const * text
) {
62 } else if (c
== L
'$') {
63 buffer
= commandLineAppend(buffer
, MY_STRING(L
"\\$"));
65 } else if (c
== L
'\\') {
66 buffer
= commandLineAppend(buffer
, MY_STRING(L
"\\\\"));
73 // The command line will continue with a double quote, so double any
74 // preceding backslashes as required by Windows:
75 for (std::size_t i
= 0; i
< n
; ++i
) {
82 // Set the PATH environment variable in the current (loader) process, so that a
83 // following CreateProcess has the necessary environment:
86 // Must point to an array of size at least MAX_PATH. Is filled with the null
87 // terminated full path to the "bin" file corresponding to the current
90 // @param iniDirectory
91 // Must point to an array of size at least MAX_PATH. Is filled with the null
92 // terminated full directory path (ending in "\") to the "ini" file
93 // corresponding to the current executable.
94 void extendLoaderEnvironment(WCHAR
* binPath
, WCHAR
* iniDirectory
);