Skip to content

Commit

Permalink
fixed path native check and implemented runtime path conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mduft committed Apr 8, 2014
1 parent a4cb5b7 commit 50154bd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
70 changes: 69 additions & 1 deletion parity.runtime/pcrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,74 @@ const char* PcrtPathToNative(const char* ptr) {

return pRing[iRingNum];
}
} else if((szRoot = GetEnvironmentVariable("REX_ROOTS", 0, 0)) != 0) {
char* ptrRoots = HeapAlloc(GetProcessHeap(), 0, szRoot);

if(GetEnvironmentVariable("REX_ROOTS", ptrRoots, szRoot)) {
// pair separated by ',' values in pair separated by ';', server path first, then client path
// -> <server1>;<client1>,<server2>;<client2>,...
int lenClient, lenServer, found = 0;
char lookBehind = 0;
char *ptrServer, *ptrClient, *ptrFix, *ptrPairEnd;
char* ptrWalk = ptrRoots;

do {
ptrPairEnd = strchr(ptrWalk, ',');
if(ptrPairEnd != NULL) {
*ptrPairEnd = 0;
}

ptrServer = ptrWalk;
ptrClient = strchr(ptrServer, ';');

if(!ptrClient) {
continue;
}

*ptrClient = 0;
++ptrClient;

// now we have one client -> server mapping pair available
lenClient = lstrlen(ptrClient);
if(CompareString(LOCALE_USER_DEFAULT, 0, ptrClient, lenClient, ptr, lenClient) == CSTR_EQUAL) {
found = 1;
pRing[iRingNum] = HeapAlloc(GetProcessHeap(), 0, lstrlen(ptr) + lstrlen(ptrServer) + 2);

lenServer = lstrlen(ptrServer);
lstrcpyn(pRing[iRingNum], ptrServer, lenServer + 1);
lstrcpyn(&pRing[iRingNum][lenServer + 1], &ptr[lenClient], lstrlen(&ptr[lenClient]) + 1);
pRing[iRingNum][lenServer] = '/';

// consolidate string - convert '/' -> '\' and remove all duplicate '/' and '\'
ptrFix = pRing[iRingNum];
ptrWalk = pRing[iRingNum];
while(*ptrWalk != 0) {
switch(*ptrWalk) {
case '/':
case '\\':
if(lookBehind != '\\') {
*ptrFix++ = '\\';
}
break;
default:
*ptrFix++ = *ptrWalk;
}

lookBehind = *(ptrFix - 1);
ptrWalk++;
}
*ptrFix = 0;

HeapFree(GetProcessHeap(), 0, ptrRoots);
return pRing[iRingNum];
}

if(ptrPairEnd != NULL) {
ptrWalk = ptrPairEnd + 1;
}
} while(ptrPairEnd != NULL);
}
HeapFree(GetProcessHeap(), 0, ptrRoots);
} else {
static HMODULE hCygLib = NULL;
static int inited = 0;
Expand Down Expand Up @@ -144,7 +212,7 @@ const char* PcrtPathToNative(const char* ptr) {
PcrtOutPrint(GetStdHandle(STD_ERROR_HANDLE), "Cannot load all required functions from cygwin1.dll, cannot convert absolute UNIX paths!\n");
}
} else {
PcrtOutPrint(GetStdHandle(STD_ERROR_HANDLE), "Neither Interix Installation nor Cygwin DLL found, cannot convert absolute UNIX paths!\n");
PcrtOutPrint(GetStdHandle(STD_ERROR_HANDLE), "Neither REX, Interix Installation, or Cygwin DLL found, cannot convert absolute UNIX paths!\n");
}
}

Expand Down
2 changes: 1 addition & 1 deletion parity.utils/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ namespace parity
if(path_.empty())
return true;

if(path_[0] == '.')
if(path_[0] == '.' || path_[0] == '/')
return true;

if(::strchr(path_.c_str(), '\\') || ::strchr(path_.c_str(), ':'))
Expand Down

0 comments on commit 50154bd

Please sign in to comment.