@@ -473,28 +473,34 @@ static REBSER *Read_All_File(char *fname)
473
473
*/ REBNATIVE (to_real_file )
474
474
/*
475
475
// to-real-file: native [
476
- // "Returns canonicalized absolute pathname or none if path does not exists. Resolves symbolic links. "
476
+ // "Returns canonicalized absolute pathname. On Posix resolves symbolic links and returns NONE if file does not exists! "
477
477
// path [file! string!]
478
478
// ]
479
479
***********************************************************************/
480
480
{
481
481
REBVAL * path = D_ARG (1 );
482
- REBINT len ;
483
- REBSER * ser ;
482
+ REBSER * ser = NULL ;
484
483
REBSER * new ;
485
- char * tmp ;
486
-
487
- ser = Value_To_OS_Path (path , TRUE);
488
- tmp = OS_REAL_PATH (cs_cast (VAL_BIN (path )));
489
- if (!tmp ) {
484
+ REBCHR * tmp ;
485
+ // First normalize to OS native wide string
486
+ ser = Value_To_OS_Path (path , FALSE);
487
+ // Above function does . and .. pre-processing, which does also the OS_REAL_PATH.
488
+ // So it could be replaced with version, which just prepares the input to required OS wide!
489
+ if (!ser ) {
490
490
FREE_SERIES (ser );
491
491
return R_NONE ;
492
492
}
493
- len = strlen (tmp );
494
- new = To_REBOL_Path (tmp , len , OS_WIDE , FALSE);
493
+ // Try to call realpath on posix or _fullpath on Windows
494
+ // Returned string must be released once done!
495
+ tmp = OS_REAL_PATH (SERIES_DATA (ser ));
496
+ if (!tmp ) return R_NONE ;
497
+
498
+ // Convert OS native wide string back to Rebol file type
499
+ new = To_REBOL_Path (tmp , 0 , OS_WIDE , FALSE);
500
+ OS_FREE (tmp );
501
+ if (!new ) return R_NONE ;
502
+
495
503
Set_Series (REB_FILE , D_RET , new );
496
- FREE_SERIES (ser );
497
- FREE_MEM (tmp );
498
504
return R_RET ;
499
505
}
500
506
0 commit comments