]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
Comment's added and fixed.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cd.c
index 78403c22748bae815907aed756d1dd99a02a9047..bee4b0ae43989d8486fa5b3e8acced18b6a9034f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -186,17 +186,33 @@ ShellCommandRunCd (
         // change directory on other drive letter\r
         //\r
         Drive = AllocateZeroPool(StrSize(Param1));\r
-        Drive = StrCpy(Drive, Param1);\r
-        Path = StrStr(Drive, L":");\r
-        *(++Path) = CHAR_NULL;\r
-        Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);\r
-\r
-        if (Status == EFI_NOT_FOUND) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
-          Status = SHELL_NOT_FOUND;\r
-        } else if (EFI_ERROR(Status)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r
-          Status = SHELL_NOT_FOUND;\r
+        if (Drive == NULL) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        } else {\r
+          Drive = StrCpy(Drive, Param1);\r
+          Path = StrStr(Drive, L":");\r
+          ASSERT(Path != NULL);\r
+          if (*(Path+1) == CHAR_NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+            ShellStatus = SHELL_NOT_FOUND;\r
+          } else {\r
+            *(Path+1) = CHAR_NULL;\r
+            if (Path == Drive + StrLen(Drive)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            } else {\r
+              Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+            }\r
+          }\r
+          if (Status == EFI_NOT_FOUND) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+            Status = SHELL_NOT_FOUND;\r
+          } else if (EFI_ERROR(Status)) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r
+            Status = SHELL_NOT_FOUND;\r
+          }\r
         }\r
       }\r
     }\r