Author: hbelusca Date: Tue Jun 28 19:21:08 2016 New Revision: 71692
URL: http://svn.reactos.org/svn/reactos?rev=71692&view=rev Log: [SUBST]: CORE-10681 #comment Apply part of Peter Hater's patch proposed in CORE-10681, that is, fixing the usage of QueryDosDevice API, but without the new IsDriveUsed functionality. (r71692)
Modified: trunk/reactos/base/system/subst/subst.c
Modified: trunk/reactos/base/system/subst/subst.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/subst/subst.c?r... ============================================================================== --- trunk/reactos/base/system/subst/subst.c [iso-8859-1] (original) +++ trunk/reactos/base/system/subst/subst.c [iso-8859-1] Tue Jun 28 19:21:08 2016 @@ -75,81 +75,71 @@ if (_tcslen(Drive) > 2) return FALSE;
- dwSize = sizeof(TCHAR) * MAX_PATH; - lpTargetPath = (LPTSTR) malloc(sizeof(TCHAR) * MAX_PATH); - if ( lpTargetPath) - { + dwSize = MAX_PATH; + lpTargetPath = (LPTSTR)malloc(sizeof(TCHAR) * dwSize); + if (!lpTargetPath) + return FALSE; + + CharCount = QueryDosDevice(Drive, + lpTargetPath, + dwSize); + while (!CharCount && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + lpTargetPath = (LPTSTR)realloc(lpTargetPath, sizeof(TCHAR) * dwSize); + if (lpTargetPath) + { + CharCount = QueryDosDevice(Drive, + lpTargetPath, + dwSize); + } + } + + if (CharCount) + { + Result = _tcsncmp(lpTargetPath, _T("\??\"), 4) == 0 && + ( (lpTargetPath[4] >= _T('A') && + lpTargetPath[4] <= _T('Z')) || + (lpTargetPath[4] >= _T('a') && + lpTargetPath[4] <= _T('z')) ); + } + + free(lpTargetPath); + + return Result; +} + +void DumpSubstedDrives(void) +{ + TCHAR Drive[3] = _T("A:"); + LPTSTR lpTargetPath = NULL; + DWORD CharCount, dwSize; + INT i = 0; + + dwSize = MAX_PATH; + lpTargetPath = (LPTSTR)malloc(sizeof(TCHAR) * dwSize); + if (!lpTargetPath) + return; + + while (i < 26) + { + Drive[0] = _T('A') + i; CharCount = QueryDosDevice(Drive, lpTargetPath, - dwSize / sizeof(TCHAR)); - while (! CharCount && + dwSize); + while (!CharCount && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - free(lpTargetPath); - dwSize *= 2; - lpTargetPath = (LPTSTR) malloc(dwSize); + lpTargetPath = (LPTSTR)realloc(lpTargetPath, sizeof(TCHAR) * dwSize); if (lpTargetPath) { CharCount = QueryDosDevice(Drive, lpTargetPath, - dwSize / sizeof(TCHAR)); + dwSize); } }
if (CharCount) - { - if ( _tcsncmp(lpTargetPath, _T("\??\"), 4) == 0 && - ( (lpTargetPath[4] >= _T('A') && - lpTargetPath[4] <= _T('Z')) || - (lpTargetPath[4] >= _T('a') && - lpTargetPath[4] <= _T('z')) ) ) - { - Result = TRUE; - } - } - free(lpTargetPath); - } - return Result; -} - -void DumpSubstedDrives(void) -{ - TCHAR Drive[3] = _T("A:"); - LPTSTR lpTargetPath = NULL; - DWORD CharCount, dwSize; - INT i = 0; - - dwSize = sizeof(TCHAR) * MAX_PATH; - lpTargetPath = (LPTSTR) malloc(sizeof(TCHAR) * MAX_PATH); - if (! lpTargetPath) - return; - - while (i < 26) - { - Drive[0] = _T('A') + i; - CharCount = QueryDosDevice(Drive, - lpTargetPath, - dwSize / sizeof(TCHAR)); - while (! CharCount && - GetLastError() == ERROR_INSUFFICIENT_BUFFER) - { - free(lpTargetPath); - dwSize *= 2; - lpTargetPath = (LPTSTR) malloc(dwSize); - if (lpTargetPath) - { - CharCount = QueryDosDevice(Drive, - lpTargetPath, - dwSize / sizeof(TCHAR)); - } - } - - if (! CharCount) - { - i++; - continue; - } - else { if ( _tcsncmp(lpTargetPath, _T("\??\"), 4) == 0 && ( (lpTargetPath[4] >= _T('A') && @@ -162,8 +152,10 @@ lpTargetPath + 4); } } + i++; } + free(lpTargetPath); }