Skip to content

Commit

Permalink
tryfix abspath c func with "" on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Nov 12, 2023
1 parent f6cb684 commit 1a76013
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,33 @@ static char *abspath(const char *in, int nprefix)
}
}
#else
DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL);
if (n <= 0) {
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
// GetFullPathName intentionally errors if given an empty string so manually insert cwd
if (strlen(in) - nprefix == 0) {
size_t sz = strlen(in + nprefix) + 1;
size_t path_size = JL_PATH_MAX;
char *path = (char*)malloc_s(JL_PATH_MAX);
if (uv_cwd(path, &path_size)) {
jl_error("fatal error: unexpected error while retrieving current working directory");
}
char *out = (char*)malloc_s(path_size + 1 + sz + nprefix);
memcpy(out, in, nprefix);
memcpy(out + nprefix, path, path_size);
out[nprefix + path_size] = PATHSEPSTRING[0];
memcpy(out + nprefix + path_size + 1, in + nprefix, sz);
free(path);
}
char *out = (char*)malloc_s(n + nprefix);
DWORD m = GetFullPathName(in + nprefix, n, out + nprefix, NULL);
if (n != m + 1) {
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
else {
DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL);
if (n <= 0) {
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
}
char *out = (char*)malloc_s(n + nprefix);
DWORD m = GetFullPathName(in + nprefix, n, out + nprefix, NULL);
if (n != m + 1) {
jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed");
}
memcpy(out, in, nprefix);
}
memcpy(out, in, nprefix);
#endif
return out;
}
Expand Down

0 comments on commit 1a76013

Please sign in to comment.