Skip to content

Commit 40fd23b

Browse files
author
grzegok
committed
FR #127 Normalize bin in the searched path, handle wrong path
separators.
1 parent 35522c3 commit 40fd23b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

head/head.o

384 Bytes
Binary file not shown.

head_src/head.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,16 +932,33 @@ BOOL bundledJreSearch(const char *exePath, const int pathLen)
932932

933933
while (path != NULL)
934934
{
935-
if (*path == '\\' || (*path != '\0' && *(path + 1) == ':'))
935+
char pathNoBin[_MAX_PATH] = {0};
936+
char *lastBackslash = strrchr(path, '\\');
937+
char *lastSlash = strrchr(path, '/');
938+
939+
if (lastBackslash != NULL && strcasecmp(lastBackslash, "\\bin") == 0)
940+
{
941+
strncpy(pathNoBin, path, lastBackslash - path);
942+
}
943+
else if (lastSlash != NULL && strcasecmp(lastSlash, "/bin") == 0)
944+
{
945+
strncpy(pathNoBin, path, lastSlash - path);
946+
}
947+
else
948+
{
949+
strcpy(pathNoBin, path);
950+
}
951+
952+
if (*pathNoBin == '\\' || (*pathNoBin != '\0' && *(pathNoBin + 1) == ':'))
936953
{
937954
// Absolute
938-
strcpy(launcher.cmd, path);
955+
strcpy(launcher.cmd, pathNoBin);
939956
}
940957
else
941958
{
942959
// Relative
943960
strncpy(launcher.cmd, exePath, pathLen);
944-
appendPath(launcher.cmd, path);
961+
appendPath(launcher.cmd, pathNoBin);
945962
}
946963

947964
if (isLauncherPathValid(launcher.cmd))

0 commit comments

Comments
 (0)