Kaydet (Commit) d2bf7caf authored tarafından Mike Kaganski's avatar Mike Kaganski

loader: don't use 8-bit string functions

Change-Id: I13f4fcf86dd385cecfa0a8cfd34037352a42253f
Reviewed-on: https://gerrit.libreoffice.org/42302Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 48305927
...@@ -17,42 +17,21 @@ ...@@ -17,42 +17,21 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#define UNICODE
#define _UNICODE
#define WIN32_LEAN_AND_MEAN
#if defined _MSC_VER
#pragma warning(push, 1)
#endif
#include <windows.h>
#include <shellapi.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#include <tchar.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <systools/win32/uwinapi.h>
#include <tools/pathutils.hxx> #include <tools/pathutils.hxx>
#include "../loader.hxx" #include "../loader.hxx"
static int GenericMain() static int GenericMain()
{ {
TCHAR szTargetFileName[MAX_PATH]; WCHAR szTargetFileName[MAX_PATH];
TCHAR szIniDirectory[MAX_PATH]; WCHAR szIniDirectory[MAX_PATH];
STARTUPINFO aStartupInfo; STARTUPINFOW aStartupInfo;
desktop_win32::extendLoaderEnvironment(szTargetFileName, szIniDirectory); desktop_win32::extendLoaderEnvironment(szTargetFileName, szIniDirectory);
ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) ); ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) );
aStartupInfo.cb = sizeof(aStartupInfo); aStartupInfo.cb = sizeof(aStartupInfo);
GetStartupInfo( &aStartupInfo ); GetStartupInfoW( &aStartupInfo );
DWORD dwExitCode = (DWORD)-1; DWORD dwExitCode = (DWORD)-1;
...@@ -70,9 +49,9 @@ static int GenericMain() ...@@ -70,9 +49,9 @@ static int GenericMain()
tools::buildPath( tools::buildPath(
redirect, szIniDirectory, szIniDirectory + iniDirLen, redirect, szIniDirectory, szIniDirectory + iniDirLen,
MY_STRING(L"redirect.ini")) != nullptr && MY_STRING(L"redirect.ini")) != nullptr &&
(GetBinaryType(redirect, &dummy) || // cheaper check for file existence? (GetBinaryTypeW(redirect, &dummy) || // cheaper check for file existence?
GetLastError() != ERROR_FILE_NOT_FOUND); GetLastError() != ERROR_FILE_NOT_FOUND);
LPTSTR cl1 = GetCommandLine(); LPWSTR cl1 = GetCommandLineW();
WCHAR * cl2 = new WCHAR[ WCHAR * cl2 = new WCHAR[
wcslen(cl1) + wcslen(cl1) +
(hasRedirect (hasRedirect
...@@ -98,7 +77,7 @@ static int GenericMain() ...@@ -98,7 +77,7 @@ static int GenericMain()
} }
desktop_win32::commandLineAppend(p, MY_STRING(L"\"")); desktop_win32::commandLineAppend(p, MY_STRING(L"\""));
BOOL fSuccess = CreateProcess( BOOL fSuccess = CreateProcessW(
szTargetFileName, szTargetFileName,
cl2, cl2,
nullptr, nullptr,
...@@ -127,7 +106,7 @@ static int GenericMain() ...@@ -127,7 +106,7 @@ static int GenericMain()
{ {
MSG msg; MSG msg;
PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ); PeekMessageW( &msg, nullptr, 0, 0, PM_REMOVE );
} }
} while ( WAIT_OBJECT_0 + 1 == dwWaitResult ); } while ( WAIT_OBJECT_0 + 1 == dwWaitResult );
...@@ -141,12 +120,12 @@ static int GenericMain() ...@@ -141,12 +120,12 @@ static int GenericMain()
return dwExitCode; return dwExitCode;
} }
int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{ {
return GenericMain(); return GenericMain();
} }
int __cdecl _tmain() int __cdecl wmain()
{ {
return GenericMain(); return GenericMain();
} }
......
...@@ -17,22 +17,8 @@ ...@@ -17,22 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#define WIN32_LEAN_AND_MEAN
#if defined _MSC_VER
#pragma warning(push, 1)
#endif
#include <windows.h>
#include <shlwapi.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#include <tools/pathutils.hxx> #include <tools/pathutils.hxx>
#include "loader.hxx" #include "loader.hxx"
#include <cassert> #include <cassert>
namespace { namespace {
......
...@@ -20,11 +20,9 @@ ...@@ -20,11 +20,9 @@
#ifndef INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX #ifndef INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX
#define INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX #define INCLUDED_DESKTOP_WIN32_SOURCE_LOADER_HXX
#include <sal/config.h> #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <cstddef> #include <string.h>
#include <tchar.h>
#define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1) #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
#define MY_STRING(s) (s), MY_LENGTH(s) #define MY_STRING(s) (s), MY_LENGTH(s)
......
...@@ -17,50 +17,23 @@ ...@@ -17,50 +17,23 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#define UNICODE
#define _UNICODE
#include <cstddef> #include <cstddef>
#include <cwchar>
#define WIN32_LEAN_AND_MEAN
#if defined _MSC_VER
#pragma warning(push, 1)
#endif
#include <windows.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#include <tchar.h>
#include <string.h>
#include <stdlib.h>
#include <systools/win32/uwinapi.h> #include <systools/win32/uwinapi.h>
#include <desktop/exithelper.h> #include <desktop/exithelper.h>
#include <rtl/string.h>
#include <sal/macros.h>
#include "../loader.hxx" #include "../loader.hxx"
#include <config_version.h> static LPWSTR *GetCommandArgs( int *pArgc )
static LPTSTR *GetCommandArgs( int *pArgc )
{ {
#ifdef UNICODE
return CommandLineToArgvW( GetCommandLineW(), pArgc ); return CommandLineToArgvW( GetCommandLineW(), pArgc );
#else
*pArgc = __argc;
return __argv;
#endif
} }
int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{ {
TCHAR szTargetFileName[MAX_PATH] = TEXT(""); WCHAR szTargetFileName[MAX_PATH] = {};
TCHAR szIniDirectory[MAX_PATH]; WCHAR szIniDirectory[MAX_PATH];
STARTUPINFO aStartupInfo; STARTUPINFOW aStartupInfo;
desktop_win32::extendLoaderEnvironment(szTargetFileName, szIniDirectory); desktop_win32::extendLoaderEnvironment(szTargetFileName, szIniDirectory);
...@@ -69,7 +42,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -69,7 +42,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
// Create process with same command line, environment and stdio handles which // Create process with same command line, environment and stdio handles which
// are directed to the created pipes // are directed to the created pipes
GetStartupInfo(&aStartupInfo); GetStartupInfoW(&aStartupInfo);
// If this process hasn't its stdio handles set, then check if its parent // If this process hasn't its stdio handles set, then check if its parent
// has a console (i.e. this process is launched from command line), and if so, // has a console (i.e. this process is launched from command line), and if so,
...@@ -81,9 +54,9 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -81,9 +54,9 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
DWORD dwExitCode = (DWORD)-1; DWORD dwExitCode = (DWORD)-1;
BOOL fSuccess = FALSE; BOOL fSuccess = FALSE;
LPTSTR lpCommandLine = nullptr; LPWSTR lpCommandLine = nullptr;
int argc = 0; int argc = 0;
LPTSTR * argv = nullptr; LPWSTR * argv = nullptr;
bool bFirst = true; bool bFirst = true;
WCHAR cwd[MAX_PATH]; WCHAR cwd[MAX_PATH];
DWORD cwdLen = GetCurrentDirectoryW(MAX_PATH, cwd); DWORD cwdLen = GetCurrentDirectoryW(MAX_PATH, cwd);
...@@ -126,8 +99,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -126,8 +99,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
desktop_win32::commandLineAppend(p, MY_STRING(L"\"")); desktop_win32::commandLineAppend(p, MY_STRING(L"\""));
bFirst = false; bFirst = false;
TCHAR szParentProcessId[64]; // This is more than large enough for a 128 bit decimal value WCHAR szParentProcessId[64]; // This is more than large enough for a 128 bit decimal value
BOOL bHeadlessMode( FALSE ); BOOL bHeadlessMode( FALSE );
{ {
// Check command line arguments for "--headless" parameter. We only // Check command line arguments for "--headless" parameter. We only
...@@ -135,8 +108,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -135,8 +108,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
// mode as self-destruction of the soffice.bin process can lead to // mode as self-destruction of the soffice.bin process can lead to
// certain side-effects (log-off can result in data-loss, ".lock" is not deleted. // certain side-effects (log-off can result in data-loss, ".lock" is not deleted.
// See 138244 for more information. // See 138244 for more information.
int argc2; int argc2;
LPTSTR *argv2 = GetCommandArgs( &argc2 ); LPWSTR *argv2 = GetCommandArgs( &argc2 );
if ( argc2 > 1 ) if ( argc2 > 1 )
{ {
...@@ -144,8 +117,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -144,8 +117,8 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
for ( n = 1; n < argc2; n++ ) for ( n = 1; n < argc2; n++ )
{ {
if ( 0 == _tcsnicmp( argv2[n], _T("-headless"), 9 ) || if ( 0 == wcsnicmp( argv2[n], L"-headless", 9 ) ||
0 == _tcsnicmp( argv2[n], _T("--headless"), 10 ) ) 0 == wcsnicmp( argv2[n], L"--headless", 10 ) )
{ {
bHeadlessMode = TRUE; bHeadlessMode = TRUE;
} }
...@@ -153,12 +126,12 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -153,12 +126,12 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
} }
} }
if ( _ltot( (long)GetCurrentProcessId(),szParentProcessId, 10 ) && bHeadlessMode ) if ( _ltow( (long)GetCurrentProcessId(),szParentProcessId, 10 ) && bHeadlessMode )
SetEnvironmentVariable( TEXT("ATTACHED_PARENT_PROCESSID"), szParentProcessId ); SetEnvironmentVariableW( L"ATTACHED_PARENT_PROCESSID", szParentProcessId );
PROCESS_INFORMATION aProcessInfo; PROCESS_INFORMATION aProcessInfo;
fSuccess = CreateProcess( fSuccess = CreateProcessW(
szTargetFileName, szTargetFileName,
lpCommandLine, lpCommandLine,
nullptr, nullptr,
...@@ -185,7 +158,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) ...@@ -185,7 +158,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
{ {
MSG msg; MSG msg;
PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ); PeekMessageW( &msg, nullptr, 0, 0, PM_REMOVE );
} }
} while ( WAIT_OBJECT_0 + 1 == dwWaitResult ); } while ( WAIT_OBJECT_0 + 1 == dwWaitResult );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment