Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XERCESC-2190: Remove deprecated getVersionEx #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 26 additions & 95 deletions src/xercesc/util/FileManagers/WindowsFileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ static bool isBackSlash(XMLCh c) {

WindowsFileMgr::WindowsFileMgr()
{
// Figure out if we are on NT and save that flag for later use
OSVERSIONINFO OSVer;
OSVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&OSVer);
_onNT = (OSVer.dwPlatformId == VER_PLATFORM_WIN32_NT);
}


Expand Down Expand Up @@ -138,38 +133,17 @@ WindowsFileMgr::fileOpen(const XMLCh* fileName, bool toWrite, MemoryManager* con
nameToOpen = tmpUName;
}
FileHandle retVal = 0;
if (_onNT)
{
retVal = ::CreateFileW
(
(LPCWSTR) nameToOpen
, toWrite?GENERIC_WRITE:GENERIC_READ
, FILE_SHARE_READ
, 0
, toWrite?CREATE_ALWAYS:OPEN_EXISTING
, toWrite?FILE_ATTRIBUTE_NORMAL:FILE_FLAG_SEQUENTIAL_SCAN
, 0
);
}
else
{
//
// We are Win 95 / 98. Take the Unicode file name back to (char *)
// so that we can open it.
//
char* tmpName = XMLString::transcode(nameToOpen, manager);
retVal = ::CreateFileA
(
tmpName
, toWrite?GENERIC_WRITE:GENERIC_READ
, FILE_SHARE_READ
, 0
, toWrite?CREATE_ALWAYS:OPEN_EXISTING
, toWrite?FILE_ATTRIBUTE_NORMAL:FILE_FLAG_SEQUENTIAL_SCAN
, 0
);
manager->deallocate(tmpName);//delete [] tmpName;
}

retVal = ::CreateFileW
(
(LPCWSTR) nameToOpen
, toWrite?GENERIC_WRITE:GENERIC_READ
, FILE_SHARE_READ
, 0
, toWrite?CREATE_ALWAYS:OPEN_EXISTING
, toWrite?FILE_ATTRIBUTE_NORMAL:FILE_FLAG_SEQUENTIAL_SCAN
, 0
);

if (tmpUName)
manager->deallocate(tmpUName);//delete [] tmpUName;
Expand Down Expand Up @@ -320,76 +294,33 @@ WindowsFileMgr::fileWrite(FileHandle f, XMLSize_t byteCount, const XMLByte* buff
XMLCh*
WindowsFileMgr::getFullPath(const XMLCh* const srcPath, MemoryManager* const manager)
{
//
// If we are on NT, then use wide character APIs, else use ASCII APIs.
// We have to do it manually since we are only built in ASCII mode from
// the standpoint of the APIs.
//
if (_onNT)
{
// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 1024;
XMLCh tmpPath[bufSize + 1];

XMLCh* namePart = 0;
if (!::GetFullPathNameW((LPCWSTR)srcPath, bufSize, (LPWSTR)tmpPath, (LPWSTR*)&namePart))
return 0;
// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 1024;
XMLCh tmpPath[bufSize + 1];

// Return a copy of the path
return XMLString::replicate(tmpPath, manager);
}
else
{
// Transcode the incoming string
char* tmpSrcPath = XMLString::transcode(srcPath, manager);
ArrayJanitor<char> janSrcPath(tmpSrcPath, manager);

// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 511;
char tmpPath[511 + 1];
XMLCh* namePart = 0;
if (!::GetFullPathNameW((LPCWSTR)srcPath, bufSize, (LPWSTR)tmpPath, (LPWSTR*)&namePart))
return 0;

char* namePart = 0;
if (!::GetFullPathNameA(tmpSrcPath, bufSize, tmpPath, &namePart))
return 0;
// Return a copy of the path
return XMLString::replicate(tmpPath, manager);

// Return a transcoded copy of the path
return XMLString::transcode(tmpPath, manager);
}
}


XMLCh*
WindowsFileMgr::getCurrentDirectory(MemoryManager* const manager)
{
//
// If we are on NT, then use wide character APIs, else use ASCII APIs.
// We have to do it manually since we are only built in ASCII mode from
// the standpoint of the APIs.
//
if (_onNT)
{
// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 1024;
XMLCh tmpPath[bufSize + 1];

if (!::GetCurrentDirectoryW(bufSize, (LPWSTR)tmpPath))
return 0;

// Return a copy of the path
return XMLString::replicate(tmpPath, manager);
}
else
{
// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 511;
char tmpPath[511 + 1];
// Use a local buffer that is big enough for the largest legal path
const unsigned int bufSize = 1024;
XMLCh tmpPath[bufSize + 1];

if (!::GetCurrentDirectoryA(bufSize, tmpPath))
return 0;
if (!::GetCurrentDirectoryW(bufSize, (LPWSTR)tmpPath))
return 0;

// Return a transcoded copy of the path
return XMLString::transcode(tmpPath, manager);
}
// Return a copy of the path
return XMLString::replicate(tmpPath, manager);
}


Expand Down
1 change: 0 additions & 1 deletion src/xercesc/util/FileManagers/WindowsFileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class WindowsFileMgr : public XMLFileMgr
virtual bool isRelative(const XMLCh* const toCheck, MemoryManager* const manager);

private:
bool _onNT;
};

XERCES_CPP_NAMESPACE_END
Expand Down
12 changes: 2 additions & 10 deletions src/xercesc/util/Transcoders/Win32/Win32TransService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include "Win32TransService.hpp"

#include <versionhelpers.h>
XERCES_CPP_NAMESPACE_BEGIN


Expand Down Expand Up @@ -317,15 +317,7 @@ Win32TransService::Win32TransService(MemoryManager* manager) :
{
// Figure out if we are on XP or later and save that flag for later use.
// We need this because of certain code page conversion calls.
OSVERSIONINFO OSVer;
OSVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&OSVer);

if ((OSVer.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
(OSVer.dwMajorVersion > 5 || (OSVer.dwMajorVersion == 5 && OSVer.dwMinorVersion > 0)))
{
onXPOrLater = true;
}
onXPOrLater = IsWindowsXPOrGreater();

fCPMap = new RefHashTableOf<CPMapEntry>(109);

Expand Down