@@ -575,16 +575,33 @@ static char *abspath(const char *in, int nprefix)
575
575
}
576
576
}
577
577
#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 );
581
592
}
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 );
586
604
}
587
- memcpy (out , in , nprefix );
588
605
#endif
589
606
return out ;
590
607
}
0 commit comments