From 75ef572207bfbe61cb38a043404e306886aa60e2 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 21 Mar 2001 22:25:32 +0000 Subject: [PATCH] Changed GetLong/ShortPath to allocate memory dynamically git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/filename.cpp | 54 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 87da62de5c..5e4f6beaad 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -493,22 +493,23 @@ wxString wxFileName::GetShortPath() const { #if defined(__WXMSW__) && defined(__WIN32__) wxString path(GetFullPath()); - - wxChar outBuf[MAX_PATH]; - - // TODO: can't work out how to determine if the function failed - // (positive value if either it succeeded or the buffer was too small) - - int bufSz = ::GetShortPathName((const wxChar*) path, outBuf, MAX_PATH*sizeof(wxChar)); - - if (bufSz == 0) + wxString pathOut; + DWORD sz = ::GetShortPathName(path, NULL, 0); + bool ok = sz != 0; + if ( ok ) { - return wxEmptyString; + ok = ::GetShortPathName + ( + path, + pathOut.GetWriteBuf(sz), + sz + ) != 0; + pathOut.UngetWriteBuf(); } + if (ok) + return pathOut; else - { - return wxString(outBuf); - } + return path; #else return GetFullPath(); #endif @@ -519,22 +520,23 @@ wxString wxFileName::GetLongPath() const { #if defined(__WXMSW__) && defined(__WIN32__) wxString path(GetFullPath()); - - wxChar outBuf[MAX_PATH]; - - // TODO: can't work out how to determine if the function failed - // (positive value if either it succeeded or the buffer was too small) - - int bufSz = ::GetLongPathName((const wxChar*) path, outBuf, MAX_PATH*sizeof(wxChar)); - - if (bufSz == 0) + wxString pathOut; + DWORD sz = ::GetLongPathName(path, NULL, 0); + bool ok = sz != 0; + if ( ok ) { - return wxEmptyString; + ok = ::GetLongPathName + ( + path, + pathOut.GetWriteBuf(sz), + sz + ) != 0; + pathOut.UngetWriteBuf(); } + if (ok) + return pathOut; else - { - return wxString(outBuf); - } + return path; #else return GetFullPath(); #endif -- 2.47.2