Define a name for the extended path buffer size, instead of a literal
Change-Id: If6d40c818e021b3241d6b6b33aceca07c6393511 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163926 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
parent
74185b8edf
commit
8f6b412581
14 changed files with 60 additions and 19 deletions
|
@ -23,6 +23,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
|
||||
{
|
||||
// Retrieve startup info
|
||||
|
@ -40,7 +42,7 @@ extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
|
|||
|
||||
// Calculate application name
|
||||
|
||||
WCHAR szThisAppName[32767];
|
||||
WCHAR szThisAppName[EXTENDED_MAX_PATH];
|
||||
GetModuleFileNameW(nullptr, szThisAppName, std::size(szThisAppName));
|
||||
std::filesystem::path soffice_exe(szThisAppName);
|
||||
soffice_exe.replace_filename(L"soffice.exe");
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <desktop/exithelper.h>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#include <systools/win32/uwinapi.h>
|
||||
#include <tools/pathutils.hxx>
|
||||
|
||||
|
@ -136,7 +137,7 @@ WCHAR* commandLineAppend(WCHAR* buffer, std::wstring_view text)
|
|||
// current executable.
|
||||
[[nodiscard]] std::pair<std::wstring, std::wstring> extendLoaderEnvironment()
|
||||
{
|
||||
std::vector<wchar_t> executable_path(32767);
|
||||
std::vector<wchar_t> executable_path(EXTENDED_MAX_PATH);
|
||||
DWORD exe_len;
|
||||
for (;;)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#include <tools/pathutils.hxx>
|
||||
|
||||
namespace {
|
||||
|
@ -58,7 +59,7 @@ void writePath(std::wstring_view front, std::wstring_view back)
|
|||
}
|
||||
|
||||
int wmain(int argc, wchar_t ** argv, wchar_t **) {
|
||||
wchar_t path_buf[32767];
|
||||
wchar_t path_buf[EXTENDED_MAX_PATH];
|
||||
if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
|
||||
auto path = getBrandPath(path_buf);
|
||||
writePath(path, L"");
|
||||
|
|
20
include/systools/win32/extended_max_path.hxx
Normal file
20
include/systools/win32/extended_max_path.hxx
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// The approximate maximum of Windows API, as documented in
|
||||
// https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
||||
#define EXTENDED_MAX_PATH 32767
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <cppuhelper/findsofficepath.h>
|
||||
#include <sal/types.h>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
#define MY_SIZE(s) (sizeof (s) / sizeof *(s))
|
||||
#define MY_LENGTH(s) (MY_SIZE(s) - 1)
|
||||
|
@ -72,7 +73,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||
|
||||
if ( path != NULL )
|
||||
{
|
||||
wchar_t cmd[32767];
|
||||
wchar_t cmd[EXTENDED_MAX_PATH];
|
||||
/* hopefully does not overflow */
|
||||
cmd[0] = L'"';
|
||||
wcscpy(cmd + 1, path);
|
||||
|
|
|
@ -39,11 +39,17 @@
|
|||
#include <comphelper/processfactory.hxx>
|
||||
#include <officecfg/Office/Common.hxx>
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
// apparently PATH_MAX is not standard and not defined by MSVC
|
||||
#ifndef PATH_MAX
|
||||
#ifdef _WIN32
|
||||
#define PATH_MAX 32767
|
||||
#elif defined _MAX_PATH
|
||||
#ifdef PATH_MAX
|
||||
#undef PATH_MAX
|
||||
#endif
|
||||
#define PATH_MAX EXTENDED_MAX_PATH
|
||||
#endif
|
||||
#ifndef PATH_MAX
|
||||
#if defined _MAX_PATH
|
||||
#define PATH_MAX _MAX_PATH
|
||||
#elif defined MAX_PATH
|
||||
#define PATH_MAX MAX_PATH
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#include <tools/pathutils.hxx>
|
||||
|
||||
#define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
|
||||
|
@ -64,7 +65,7 @@ static wchar_t * encode(wchar_t * buffer, wchar_t const * text) {
|
|||
}
|
||||
|
||||
int wmain(int argc, wchar_t ** argv, wchar_t **) {
|
||||
wchar_t path[32767];
|
||||
wchar_t path[EXTENDED_MAX_PATH];
|
||||
DWORD n = GetModuleFileNameW(nullptr, path, std::size(path));
|
||||
if (n == 0 || n >= std::size(path)) {
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#elif defined _WIN32
|
||||
#include <process.h>
|
||||
#include <windows.h>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#define OSL_DETAIL_GETPID _getpid()
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
@ -91,7 +92,7 @@ char const * toString(sal_detail_LogLevel level) {
|
|||
char const* setEnvFromLoggingIniFile(const char* env, const char* key)
|
||||
{
|
||||
char const* sResult = nullptr;
|
||||
wchar_t buffer[32767];
|
||||
wchar_t buffer[EXTENDED_MAX_PATH];
|
||||
DWORD nLen = GetModuleFileNameW(nullptr, buffer, std::size(buffer));
|
||||
if (nLen == 0 || nLen >= std::size(buffer))
|
||||
return sResult;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <osl/process.h>
|
||||
#include <sal/log.hxx>
|
||||
#include <systools/win32/comtools.hxx>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
|
@ -477,13 +478,13 @@ Sequence<JumpListItem> SAL_CALL JumpListImpl::getRemovedItems(const OUString& sA
|
|||
item.arguments = o3tl::toU(PropVariantToStringWithDefault(propvar, L""));
|
||||
PropVariantClear(&propvar);
|
||||
|
||||
wchar_t itemDesc[32767];
|
||||
wchar_t itemDesc[EXTENDED_MAX_PATH];
|
||||
ThrowIfFailed(pShellLinkItem->GetDescription(
|
||||
itemDesc, std::extent<decltype(itemDesc)>::value),
|
||||
"GetDescription failed.");
|
||||
item.description = o3tl::toU(itemDesc);
|
||||
|
||||
wchar_t path[32767];
|
||||
wchar_t path[EXTENDED_MAX_PATH];
|
||||
int icon_index;
|
||||
ThrowIfFailed(pShellLinkItem->GetIconLocation(
|
||||
path, std::extent<decltype(path)>::value, &icon_index),
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include <olectl.h> // declarations of DllRegisterServer/DllUnregisterServer
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
// Module global
|
||||
|
||||
LONG g_DllRefCnt = 0;
|
||||
|
@ -300,7 +302,7 @@ namespace /* private */
|
|||
|
||||
STDAPI DllRegisterServer()
|
||||
{
|
||||
WCHAR ModuleFileName[32767];
|
||||
WCHAR ModuleFileName[EXTENDED_MAX_PATH];
|
||||
|
||||
GetModuleFileNameW(
|
||||
GetCurrentModuleHandle(),
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <com/sun/star/system/XSimpleMailMessage2.hpp>
|
||||
#include <osl/file.hxx>
|
||||
#include <o3tl/char16_t2wchar_t.hxx>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#include <tools/urlobj.hxx>
|
||||
#include <unotools/pathoptions.hxx>
|
||||
#include <unotools/syslocale.hxx>
|
||||
|
@ -67,7 +68,7 @@ namespace /* private */
|
|||
LONG lret = RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\LibreOffice\\SendAsEMailClient", &hkey);
|
||||
if (lret == ERROR_SUCCESS)
|
||||
{
|
||||
wchar_t buff[32767];
|
||||
wchar_t buff[EXTENDED_MAX_PATH];
|
||||
LONG sz = sizeof(buff);
|
||||
lret = RegQueryValueW(hkey, nullptr, buff, &sz);
|
||||
if (lret == ERROR_SUCCESS)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <osl/file.hxx>
|
||||
#include <rtl/bootstrap.hxx>
|
||||
#include <spsuppStrings.hrc>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
#include <unotools/resmgr.hxx>
|
||||
#include "res/spsuppDlg.h"
|
||||
|
||||
|
@ -31,7 +32,7 @@ const OUString& GetSofficeExe()
|
|||
{
|
||||
static const OUString s_sPath = []() {
|
||||
OUString result;
|
||||
wchar_t sPath[32767];
|
||||
wchar_t sPath[EXTENDED_MAX_PATH];
|
||||
if (GetModuleFileNameW(nullptr, sPath, std::size(sPath)) == 0)
|
||||
return result;
|
||||
wchar_t* pSlashPos = wcsrchr(sPath, L'\\');
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <shlwapi.h> // declaration of DllInstall
|
||||
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
HANDLE g_hModule;
|
||||
|
@ -40,7 +42,7 @@ ITypeLib* GetTypeLib()
|
|||
typedef std::unique_ptr<ITypeLib, void(*)(IUnknown* p)> ITypeLibGuard;
|
||||
static ITypeLibGuard s_aITypeLibGuard = [] {
|
||||
ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); });
|
||||
wchar_t szFile[32767];
|
||||
wchar_t szFile[EXTENDED_MAX_PATH];
|
||||
if (GetModuleFileNameW(GetHModule(), szFile, std::size(szFile)) == 0)
|
||||
return aITypeLibGuard;
|
||||
ITypeLib* pTypeLib;
|
||||
|
@ -55,7 +57,7 @@ ITypeLib* GetTypeLib()
|
|||
const wchar_t* GetHelperExe()
|
||||
{
|
||||
static wchar_t* s_sPath = []() -> wchar_t* {
|
||||
static wchar_t sPath[32767];
|
||||
static wchar_t sPath[EXTENDED_MAX_PATH];
|
||||
if (GetModuleFileNameW(GetHModule(), sPath, std::size(sPath)) == 0)
|
||||
return nullptr;
|
||||
wchar_t* pSlashPos = wcsrchr(sPath, L'\\');
|
||||
|
@ -120,7 +122,7 @@ STDAPI DllRegisterServer(void)
|
|||
if (!pTypeLib)
|
||||
return ResultFromScode(SELFREG_E_TYPELIB);
|
||||
|
||||
wchar_t szFile[32767];
|
||||
wchar_t szFile[EXTENDED_MAX_PATH];
|
||||
if (GetModuleFileNameW(GetHModule(), szFile, std::size(szFile)) == 0)
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <iomanip>
|
||||
|
||||
#include <systools/win32/comtools.hxx>
|
||||
#include <systools/win32/extended_max_path.hxx>
|
||||
|
||||
using namespace com::sun::star::uno;
|
||||
|
||||
|
@ -322,7 +323,7 @@ static std::wstring getShellLinkTarget(const std::wstring& aLnkFile)
|
|||
if (FAILED(hr))
|
||||
return target;
|
||||
|
||||
wchar_t pathW[32767];
|
||||
wchar_t pathW[EXTENDED_MAX_PATH];
|
||||
WIN32_FIND_DATAW wfd;
|
||||
hr = pIShellLink->GetPath(pathW, std::size(pathW), &wfd, SLGP_RAWPATH);
|
||||
if (FAILED(hr))
|
||||
|
@ -381,7 +382,7 @@ css::uno::Sequence<sal_Int8> CF_HDROPToFileList(HGLOBAL hGlobal)
|
|||
|
||||
for (UINT i = 0; i < nFiles; i++)
|
||||
{
|
||||
wchar_t buff[32767];
|
||||
wchar_t buff[EXTENDED_MAX_PATH];
|
||||
/*UINT size =*/ DragQueryFileW(static_cast<HDROP>(hGlobal), i, buff, std::size(buff));
|
||||
std::wstring filename = buff;
|
||||
if (isShellLink(filename))
|
||||
|
|
Loading…
Reference in a new issue