@@ -76,7 +76,7 @@ int __inline__ pBat_Canonicalize(char* path)
7676 /* If the path is UNC, just skip the very first part */
7777 if (PBAT_TEST_UNC_PATH (path )) {
7878 path += 2 ;
79-
79+
8080 while (* path && !PBAT_TEST_SEPARATOR (path ))
8181 path ++ ;
8282
@@ -171,8 +171,9 @@ int pBat_SetCurrentDir(char* lpLine)
171171 if (* lpLine == '/' ) {
172172
173173 /* well, arguably lpCurrentDir[2] is a slash ...
174- unless lpCurrentDir refers to a unc path, but this
175- is not handled yet */
174+ unless lpCurrentDir refers to a unc path
175+ which is still unsupported */
176+
176177 strncpy (lpCurrentDir + 2 , lpLine , FILENAME_MAX - 2 );
177178 lpCurrentDir [FILENAME_MAX - 1 ] = '\0' ;
178179
@@ -402,40 +403,30 @@ int pBat_CmdCd_win(char* lpLine)
402403
403404 if (* pBat_SkipBlanks (lpLine + 2 ) == '\0' ) {
404405
405- /* only got a drive name */
406- varname [1 ] = * lpLine ;
407-
408- if (!(lpNext = pBat_GetEnv (lpeEnv , varname ))) {
409-
410- lpNext = lpLine ;
406+ /* If the only argument is a drive letter eg `x:` do the following
407+ steps :
408+ - check if `=x:` variable exists, if so change current directory to it
409+ - if no change directory to x:\ and set `=x:` accordingly */
411410
412- }
411+ force = TRUE;
413412
414- if ( pBat_SetCurrentDir ( lpNext )) {
413+ varname [ 1 ] = * lpLine ;
415414
416- pBat_ShowErrorMessage (PBAT_DIRECTORY_ERROR
417- | PBAT_PRINT_C_ERROR ,
418- lpNext ,
419- FALSE
420- );
415+ if (!(lpLine = pBat_GetEnv (lpeEnv , varname ))) {
421416
422- status = PBAT_DIRECTORY_ERROR ;
417+ /* append a slash so this becomes a valid path */
418+ lpLine = pBat_SkipBlanks (lpesStr -> str );
423419
424420 }
425-
426- goto end ;
427-
428421 }
429422
430-
431- /* get current curent directory disk */
432423 passed = * lpLine ;
433424
434425 }
435426
436427 if ((passed == 0 )
437428 || (toupper (passed ) == toupper (current ))
438- || ( force == TRUE) ) {
429+ || force ) {
439430
440431 /* change the current directory, yeah */
441432
@@ -454,8 +445,7 @@ int pBat_CmdCd_win(char* lpLine)
454445 }
455446
456447 varname [1 ] = (passed == 0 ) ? (current ) : (passed );
457-
458- pBat_SetEnv (lpeEnv , varname , lpLine );
448+ pBat_SetEnv (lpeEnv , varname , (passed == 0 ) ? lpCurrentDir : lpLine );
459449
460450end :
461451 pBat_EsFree_Cached (lpesStr );
0 commit comments