< prev index next >
make/src/native/fixpath.c
Print this page
*** 22,31 ****
--- 22,32 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <Windows.h>
+ #include <stdbool.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
*** 51,79 ****
LocalFree(lpMsgBuf);
}
/*
! * Test if pos points to /cygdrive/_/ where _ can
* be any character.
*/
! int is_cygdrive_here(int pos, char const *in, int len)
{
! // Length of /cygdrive/c/ is 12
! if (pos+12 > len) return 0;
! if (in[pos+11]=='/' &&
! in[pos+9]=='/' &&
! in[pos+8]=='e' &&
! in[pos+7]=='v' &&
! in[pos+6]=='i' &&
! in[pos+5]=='r' &&
! in[pos+4]=='d' &&
! in[pos+3]=='g' &&
! in[pos+2]=='y' &&
! in[pos+1]=='c' &&
! in[pos+0]=='/') {
! return 1;
}
return 0;
}
/*
--- 52,71 ----
LocalFree(lpMsgBuf);
}
/*
! * Test if pos points to /prefix/_/ where _ can
* be any character.
*/
! int is_prefix_here(int pos, char const *in, int len, const char* prefix)
{
! // Length of c/ is 2
! int prefix_size = strlen(prefix);
! if (pos+prefix_size+2 > len) return 0;
! if (in[pos+prefix_size+1]=='/') {
! return strncmp(in + pos, prefix, prefix_size) == 0;
}
return 0;
}
/*
*** 91,101 ****
memmove(out, in, len + 1);
return out;
}
for (i = 0, j = 0; i<len;) {
! if (is_cygdrive_here(i, in, len)) {
out[j++] = in[i+10];
out[j++] = ':';
i+=11;
} else {
out[j] = in[i];
--- 83,93 ----
memmove(out, in, len + 1);
return out;
}
for (i = 0, j = 0; i<len;) {
! if (is_prefix_here(i, in, len, "/cygdrive/")) {
out[j++] = in[i+10];
out[j++] = ':';
i+=11;
} else {
out[j] = in[i];
*** 194,204 ****
--- 186,228 ----
}
return str;
}
+ /*
+ * Replace /mnt/_/ with _:/
+ * Works in place since drive letter is always
+ * shorter than /mnt/
+ */
+ char *replace_cygdrive_wsl(char const *in)
+ {
+ size_t len = strlen(in);
+ char *out = (char*) malloc(len+1);
+ int i,j;
+
+ if (len < 7) {
+ memmove(out, in, len + 1);
+ return out;
+ }
+
+ for (i = 0, j = 0; i<len;) {
+ if (is_prefix_here(i, in, len, "/mnt/")) {
+ out[j++] = in[i+5];
+ out[j++] = ':';
+ i+=6;
+ } else {
+ out[j] = in[i];
+ i++;
+ j++;
+ }
+ }
+ out[j] = '\0';
+ return out;
+ }
+
char*(*replace_cygdrive)(char const *in) = NULL;
+ bool debug_fixpath = false;
char *files_to_delete[1024];
int num_files_to_delete = 0;
char *fix_at_file(char const *in)
*** 248,262 ****
buffer = (char*) malloc(buflen);
while ((blocklen = fread(block, 1, sizeof(block), atin)) > 0) {
append(&buffer, &buflen, &used, block, blocklen);
}
buffer[used] = 0;
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath input from @-file %s: %s\n", &in[1], buffer);
}
fixed = replace_cygdrive(buffer);
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath converted to @-file %s is: %s\n", name, fixed);
}
fwrite(fixed, strlen(fixed), 1, atout);
fclose(atin);
fclose(atout);
--- 272,286 ----
buffer = (char*) malloc(buflen);
while ((blocklen = fread(block, 1, sizeof(block), atin)) > 0) {
append(&buffer, &buflen, &used, block, blocklen);
}
buffer[used] = 0;
! if (debug_fixpath) {
fprintf(stderr, "fixpath input from @-file %s: %s\n", &in[1], buffer);
}
fixed = replace_cygdrive(buffer);
! if (debug_fixpath) {
fprintf(stderr, "fixpath converted to @-file %s is: %s\n", name, fixed);
}
fwrite(fixed, strlen(fixed), 1, atout);
fclose(atin);
fclose(atout);
*** 361,399 ****
DWORD exitCode = 0;
DWORD processFlags = 0;
BOOL processInheritHandles = TRUE;
BOOL waitForChild = TRUE;
! if (argc<2 || argv[1][0] != '-' || (argv[1][1] != 'c' && argv[1][1] != 'm')) {
! fprintf(stderr, "Usage: fixpath -c|m<path@path@...> [--detach] /cygdrive/c/WINDOWS/notepad.exe [/cygdrive/c/x/test.txt|@/cygdrive/c/x/atfile]\n");
exit(0);
}
! if (getenv("DEBUG_FIXPATH") != NULL) {
char const * cmdline = GetCommandLine();
fprintf(stderr, "fixpath input line >%s<\n", strstr(cmdline, argv[1]));
}
if (argv[1][1] == 'c' && argv[1][2] == '\0') {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath using cygwin mode\n");
}
replace_cygdrive = replace_cygdrive_cygwin;
} else if (argv[1][1] == 'm') {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath using msys mode, with path list: %s\n", &argv[1][2]);
}
setup_msys_path_list(argv[1]);
replace_cygdrive = replace_cygdrive_msys;
} else {
fprintf(stderr, "fixpath Unknown mode: %s\n", argv[1]);
exit(-1);
}
if (argv[2][0] == '-') {
if (strcmp(argv[2], "--detach") == 0) {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath in detached mode\n");
}
processFlags |= DETACHED_PROCESS;
processInheritHandles = FALSE;
waitForChild = FALSE;
--- 385,430 ----
DWORD exitCode = 0;
DWORD processFlags = 0;
BOOL processInheritHandles = TRUE;
BOOL waitForChild = TRUE;
! debug_fixpath = (getenv("DEBUG_FIXPATH") != NULL);
!
! if (argc<2 || argv[1][0] != '-' || (argv[1][1] != 'c' && argv[1][1] != 'm' && argv[1][1] != 'w')) {
! fprintf(stderr, "Usage: fixpath -c|m|w<path@path@...> [--detach] /cygdrive/c/WINDOWS/notepad.exe [/cygdrive/c/x/test.txt|@/cygdrive/c/x/atfile]\n");
exit(0);
}
! if (debug_fixpath) {
char const * cmdline = GetCommandLine();
fprintf(stderr, "fixpath input line >%s<\n", strstr(cmdline, argv[1]));
}
if (argv[1][1] == 'c' && argv[1][2] == '\0') {
! if (debug_fixpath) {
fprintf(stderr, "fixpath using cygwin mode\n");
}
replace_cygdrive = replace_cygdrive_cygwin;
} else if (argv[1][1] == 'm') {
! if (debug_fixpath) {
fprintf(stderr, "fixpath using msys mode, with path list: %s\n", &argv[1][2]);
}
setup_msys_path_list(argv[1]);
replace_cygdrive = replace_cygdrive_msys;
+ } else if (argv[1][1] == 'w') {
+ if (debug_fixpath) {
+ fprintf(stderr, "fixpath using wsl mode, with path list: %s\n", &argv[1][2]);
+ }
+ replace_cygdrive = replace_cygdrive_wsl;
} else {
fprintf(stderr, "fixpath Unknown mode: %s\n", argv[1]);
exit(-1);
}
if (argv[2][0] == '-') {
if (strcmp(argv[2], "--detach") == 0) {
! if (debug_fixpath) {
fprintf(stderr, "fixpath in detached mode\n");
}
processFlags |= DETACHED_PROCESS;
processInheritHandles = FALSE;
waitForChild = FALSE;
*** 415,425 ****
char *val = replace_cygdrive(assignment + 1);
memmove(var, argv[i], var_len);
var[var_len - 1] = '\0';
strupr(var);
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath setting var >%s< to >%s<\n", var, val);
}
rc = SetEnvironmentVariable(var, val);
if (!rc) {
--- 446,456 ----
char *val = replace_cygdrive(assignment + 1);
memmove(var, argv[i], var_len);
var[var_len - 1] = '\0';
strupr(var);
! if (debug_fixpath) {
fprintf(stderr, "fixpath setting var >%s< to >%s<\n", var, val);
}
rc = SetEnvironmentVariable(var, val);
if (!rc) {
*** 478,493 ****
memmove(current, argv[i], len);
current += len;
}
*current = '\0';
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath converted line >%s<\n", line);
}
if (cmd == argc) {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath no command provided!\n");
}
exit(0);
}
--- 509,524 ----
memmove(current, argv[i], len);
current += len;
}
*current = '\0';
! if (debug_fixpath) {
fprintf(stderr, "fixpath converted line >%s<\n", line);
}
if (cmd == argc) {
! if (debug_fixpath) {
fprintf(stderr, "fixpath no command provided!\n");
}
exit(0);
}
*** 516,526 ****
if (waitForChild == TRUE) {
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exitCode);
! if (getenv("DEBUG_FIXPATH") != NULL) {
for (i=0; i<num_files_to_delete; ++i) {
fprintf(stderr, "fixpath Not deleting temporary file %s\n",
files_to_delete[i]);
}
} else {
--- 547,557 ----
if (waitForChild == TRUE) {
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exitCode);
! if (debug_fixpath) {
for (i=0; i<num_files_to_delete; ++i) {
fprintf(stderr, "fixpath Not deleting temporary file %s\n",
files_to_delete[i]);
}
} else {
*** 528,544 ****
remove(files_to_delete[i]);
}
}
if (exitCode != 0) {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath exit code %d\n",
exitCode);
}
}
} else {
! if (getenv("DEBUG_FIXPATH") != NULL) {
fprintf(stderr, "fixpath Not waiting for child process");
}
}
exit(exitCode);
--- 559,575 ----
remove(files_to_delete[i]);
}
}
if (exitCode != 0) {
! if (debug_fixpath) {
fprintf(stderr, "fixpath exit code %d\n",
exitCode);
}
}
} else {
! if (debug_fixpath) {
fprintf(stderr, "fixpath Not waiting for child process");
}
}
exit(exitCode);
< prev index next >