Skip to content

Commit 1a76013

Browse files
tryfix abspath c func with "" on windows
1 parent f6cb684 commit 1a76013

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/init.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,16 +575,33 @@ static char *abspath(const char *in, int nprefix)
575575
}
576576
}
577577
#else
578-
DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL);
579-
if (n <= 0) {
580-
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
578+
// GetFullPathName intentionally errors if given an empty string so manually insert cwd
579+
if (strlen(in) - nprefix == 0) {
580+
size_t sz = strlen(in + nprefix) + 1;
581+
size_t path_size = JL_PATH_MAX;
582+
char *path = (char*)malloc_s(JL_PATH_MAX);
583+
if (uv_cwd(path, &path_size)) {
584+
jl_error("fatal error: unexpected error while retrieving current working directory");
585+
}
586+
char *out = (char*)malloc_s(path_size + 1 + sz + nprefix);
587+
memcpy(out, in, nprefix);
588+
memcpy(out + nprefix, path, path_size);
589+
out[nprefix + path_size] = PATHSEPSTRING[0];
590+
memcpy(out + nprefix + path_size + 1, in + nprefix, sz);
591+
free(path);
581592
}
582-
char *out = (char*)malloc_s(n + nprefix);
583-
DWORD m = GetFullPathName(in + nprefix, n, out + nprefix, NULL);
584-
if (n != m + 1) {
585-
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
593+
else {
594+
DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL);
595+
if (n <= 0) {
596+
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
597+
}
598+
char *out = (char*)malloc_s(n + nprefix);
599+
DWORD m = GetFullPathName(in + nprefix, n, out + nprefix, NULL);
600+
if (n != m + 1) {
601+
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
602+
}
603+
memcpy(out, in, nprefix);
586604
}
587-
memcpy(out, in, nprefix);
588605
#endif
589606
return out;
590607
}

0 commit comments

Comments
 (0)