* and one additional slot for a UNC name
*/
const int driveCount = ('Z'-'A')+1+1;
+const int driveLetterCount = ('Z'-'A')+1;
class VDir
{
{
char *ptr = dirTableA[index];
if (!ptr) {
- /* simulate the existance of this drive */
+ /* simulate the existence of this drive */
ptr = szLocalBufferA;
ptr[0] = 'A' + index;
ptr[1] = ':';
{
WCHAR *ptr = dirTableW[index];
if (!ptr) {
- /* simulate the existance of this drive */
+ /* simulate the existence of this drive */
ptr = szLocalBufferW;
ptr[0] = 'A' + index;
ptr[1] = ':';
else {
int bSave = bManageDirectory;
DWORD driveBits = GetLogicalDrives();
- OSVERSIONINFO osver;
-
- memset(&osver, 0, sizeof(osver));
- osver.dwOSVersionInfoSize = sizeof(osver);
- GetVersionEx(&osver);
bManageDirectory = 0;
- if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
- char szBuffer[MAX_PATH*driveCount];
- if (GetLogicalDriveStringsA(sizeof(szBuffer), szBuffer)) {
- char* pEnv = (char*)GetEnvironmentStringsA();
- char* ptr = szBuffer;
- for (index = 0; index < driveCount; ++index) {
- if (driveBits & (1<<index)) {
- ptr += SetDirA(ptr, index) + 1;
- FromEnvA(pEnv, index);
- }
+ WCHAR szBuffer[MAX_PATH*driveCount];
+ if (GetLogicalDriveStringsW(sizeof(szBuffer), szBuffer)) {
+ WCHAR* pEnv = GetEnvironmentStringsW();
+ WCHAR* ptr = szBuffer;
+ for (index = 0; index < driveCount; ++index) {
+ if (driveBits & (1<<index)) {
+ ptr += SetDirW(ptr, index) + 1;
+ FromEnvW(pEnv, index);
}
- FreeEnvironmentStringsA(pEnv);
}
- SetDefaultA(".");
- }
- else { /* Windows NT or later */
- WCHAR szBuffer[MAX_PATH*driveCount];
- if (GetLogicalDriveStringsW(sizeof(szBuffer), szBuffer)) {
- WCHAR* pEnv = GetEnvironmentStringsW();
- WCHAR* ptr = szBuffer;
- for (index = 0; index < driveCount; ++index) {
- if (driveBits & (1<<index)) {
- ptr += SetDirW(ptr, index) + 1;
- FromEnvW(pEnv, index);
- }
- }
- FreeEnvironmentStringsW(pEnv);
- }
- SetDefaultW(L".");
+ FreeEnvironmentStringsW(pEnv);
}
+ SetDefaultW(L".");
bManageDirectory = bSave;
}
}
void VDir::FromEnvA(char *pEnv, int index)
{ /* gets the directory for index from the environment variable. */
while (*pEnv != '\0') {
- if ((pEnv[0] == '=') && (DriveIndex(pEnv[1]) == index)) {
+ if ((pEnv[0] == '=') && (DriveIndex(pEnv[1]) == index)
+ && pEnv[2] == ':' && pEnv[3] == '=') {
SetDirA(&pEnv[4], index);
break;
}
void VDir::FromEnvW(WCHAR *pEnv, int index)
{ /* gets the directory for index from the environment variable. */
while (*pEnv != '\0') {
- if ((pEnv[0] == '=') && (DriveIndex((char)pEnv[1]) == index)) {
+ if ((pEnv[0] == '=') && (DriveIndex((char)pEnv[1]) == index)
+ && pEnv[2] == ':' && pEnv[3] == '=') {
SetDirW(&pEnv[4], index);
break;
}
/*
* On WinNT GetFullPathName does not fail, (or at least always
- * succeeds when the drive is valid) WinNT does set *Dest to Nullch
+ * succeeds when the drive is valid) WinNT does set *Dest to NULL
* On Win98 GetFullPathName will set last error if it fails, but
* does not touch *Dest
*/
* possiblities -- relative path or absolute path with or without drive letter
* OR UNC name
*/
+ int driveIndex;
char szBuffer[(MAX_PATH+1)*2];
char szlBuf[MAX_PATH+1];
int length = strlen(pInName);
}
/* strlen(pInName) is now <= MAX_PATH */
- if (pInName[1] == ':') {
+ if (length > 1 && pInName[1] == ':') {
/* has drive letter */
- if (IsPathSep(pInName[2])) {
+ if (length > 2 && IsPathSep(pInName[2])) {
/* absolute with drive letter */
DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
}
else {
/* relative path with drive letter */
- strcpy(szBuffer, GetDirA(DriveIndex(*pInName)));
+ driveIndex = DriveIndex(*pInName);
+ if (driveIndex < 0 || driveIndex >= driveLetterCount)
+ return (char *)pInName;
+ strcpy(szBuffer, GetDirA(driveIndex));
strcat(szBuffer, &pInName[2]);
if(strlen(szBuffer) > MAX_PATH)
szBuffer[MAX_PATH] = '\0';
}
else {
/* no drive letter */
- if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
+ if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
/* UNC name */
DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
}
/*
* On WinNT GetFullPathName does not fail, (or at least always
- * succeeds when the drive is valid) WinNT does set *Dest to Nullch
+ * succeeds when the drive is valid) WinNT does set *Dest to NULL
* On Win98 GetFullPathName will set last error if it fails, but
* does not touch *Dest
*/
* possiblities -- relative path or absolute path with or without drive letter
* OR UNC name
*/
+ int driveIndex;
WCHAR szBuffer[(MAX_PATH+1)*2];
WCHAR szlBuf[MAX_PATH+1];
int length = wcslen(pInName);
}
/* strlen(pInName) is now <= MAX_PATH */
- if (pInName[1] == ':') {
+ if (length > 1 && pInName[1] == ':') {
/* has drive letter */
if (IsPathSep(pInName[2])) {
/* absolute with drive letter */
}
else {
/* relative path with drive letter */
- wcscpy(szBuffer, GetDirW(DriveIndex((char)*pInName)));
+ driveIndex = DriveIndex(*pInName);
+ if (driveIndex < 0 || driveIndex >= driveLetterCount)
+ return (WCHAR *)pInName;
+ wcscpy(szBuffer, GetDirW(driveIndex));
wcscat(szBuffer, &pInName[2]);
if(wcslen(szBuffer) > MAX_PATH)
szBuffer[MAX_PATH] = '\0';
}
else {
/* no drive letter */
- if (IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
+ if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
/* UNC name */
DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
}