mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 20:28:30 +00:00
Perform better fixups of NT paths in execve()
This change ensures we do a better job translating /c/foo.bar paths into c:/foo.bar paths on Windows when generating the CreateProcess() cmd line thus fixing a regression that happened in the last two months when using the help() feature of Actually Portable Python in the CMD.EXE shell.
This commit is contained in:
parent
cfb5d3e406
commit
701564de19
4 changed files with 50 additions and 10 deletions
|
@ -41,6 +41,10 @@ static bool NeedsQuotes(const char *s) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline int IsAlpha(int c) {
|
||||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts System V argv to Windows-style command line.
|
||||
*
|
||||
|
@ -86,8 +90,27 @@ textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], const char *prog,
|
|||
}
|
||||
}
|
||||
if (!x) break;
|
||||
if (!i && x == '/') {
|
||||
x = '\\';
|
||||
if (x == '/' || x == '\\') {
|
||||
if (!i) {
|
||||
// turn / into \ for first arg
|
||||
x = '\\';
|
||||
// turn \c\... into c:\ for first arg
|
||||
if (k == 2 && IsAlpha(cmdline[1]) && cmdline[0] == '\\') {
|
||||
cmdline[0] = cmdline[1];
|
||||
cmdline[1] = ':';
|
||||
}
|
||||
} else {
|
||||
// turn stuff like `less /c/...`
|
||||
// into `less c:/...`
|
||||
// turn stuff like `more <\\\"/c/...\\\"`
|
||||
// into `more <\\\"c:/...\\\"`
|
||||
if (k > 3 && IsAlpha(cmdline[k - 1]) &&
|
||||
(cmdline[k - 2] == '/' || cmdline[k - 2] == '\\') &&
|
||||
(cmdline[k - 3] == '"' || cmdline[k - 3] == ' ')) {
|
||||
cmdline[k - 2] = cmdline[k - 1];
|
||||
cmdline[k - 1] = ':';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x == '\\') {
|
||||
++slashes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue