Skip to content

Commit

Permalink
Use unsafe function alternatives because they're exclusive to Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Oct 3, 2024
1 parent 85d278b commit 00ec705
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,15 @@ _TCHAR* checkPath( _TCHAR* path, _TCHAR* programDir, int reverseOrder )
_TCHAR* expandPath(_TCHAR* inPath) {
_TCHAR buffer[MAX_PATH_LENGTH];
_TCHAR variable[MAX_PATH_LENGTH];
_TCHAR value[MAX_PATH_LENGTH];

_TCHAR* dstCur = &buffer[0];
_TCHAR* dstEnd = &buffer[MAX_PATH_LENGTH];
_TCHAR* srcCur = &inPath[0];

for(;;) {
_TCHAR* start = _tcschr(srcCur, _T_ECLIPSE('%'));
if (start == NULL) {
// No more variables
_tcsncpy_s(dstCur, dstEnd - dstCur, srcCur, _TRUNCATE);
_tcscpy(dstCur, srcCur);
return _tcsdup(buffer);
}
_TCHAR* end = _tcschr(start + 1, _T_ECLIPSE('%'));
Expand All @@ -563,18 +561,18 @@ _TCHAR* expandPath(_TCHAR* inPath) {
*dstCur++ = *srcCur++;
continue;
}
_tcsncpy_s(variable, end - start, start + 1, _TRUNCATE);
size_t count;
_tgetenv_s(&count, value, MAX_PATH_LENGTH, variable);
if (count > 0) {
_tcsncpy(variable, start + 1, end - start);
variable[end - start - 1] = _T_ECLIPSE('\0');
_TCHAR* value = _tgetenv(variable);
if (value != NULL) {
// Found a variable
_tcsncpy_s(dstCur, dstEnd - dstCur, srcCur, start - srcCur);
_tcsncpy(dstCur, srcCur, start - srcCur);
dstCur += start - srcCur;
_tcsncpy_s(dstCur, dstEnd - dstCur, value, _TRUNCATE);
_tcscpy(dstCur, value);
dstCur += _tcslen(value);
} else {
// Variable is not found
_tcsncpy_s(dstCur, dstEnd - dstCur, srcCur, end - srcCur + 1);
_tcsncpy(dstCur, srcCur, end - srcCur + 1);
dstCur += end - srcCur + 1;
}
srcCur = end + 1;
Expand Down

0 comments on commit 00ec705

Please sign in to comment.