]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/SemihostLib/SemihostLib.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPkg / Library / SemihostLib / SemihostLib.c
index 5a36515b7727199da7ad4303baa09e31a93155a0..f93d7991d298dbb9b71bae9c8d15d37df075df35 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
+  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR>\r
+\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
@@ -40,6 +41,11 @@ SemihostFileOpen (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
+  // Remove any leading separator (e.g.: '\'). EFI Shell adds one.\r
+  if (*FileName == '\\') {\r
+    FileName++;\r
+  }\r
+\r
   OpenBlock.FileName    = FileName;\r
   OpenBlock.Mode        = Mode;\r
   OpenBlock.NameLength  = AsciiStrLen(FileName);\r
@@ -68,10 +74,12 @@ SemihostFileSeek (
 \r
   Result = Semihost_SYS_SEEK(&SeekBlock);\r
 \r
-  if (Result == 0) {\r
-    return RETURN_SUCCESS;\r
-  } else {\r
+  // Semihosting does not behave as documented. It returns the offset on\r
+  // success.\r
+  if (Result < 0) {\r
     return RETURN_ABORTED;\r
+  } else {\r
+    return RETURN_SUCCESS;\r
   }\r
 }\r
 \r
@@ -95,7 +103,7 @@ SemihostFileRead (
 \r
   Result = Semihost_SYS_READ(&ReadBlock);\r
 \r
-  if (Result == *Length) {\r
+  if ((*Length != 0) && (Result == *Length)) {\r
     return RETURN_ABORTED;\r
   } else {\r
     *Length -= Result;\r
@@ -121,8 +129,11 @@ SemihostFileWrite (
   WriteBlock.Length = *Length;\r
 \r
   *Length = Semihost_SYS_WRITE(&WriteBlock);\r
-  \r
-  return RETURN_SUCCESS;\r
+\r
+  if (*Length != 0)\r
+    return RETURN_ABORTED;\r
+  else\r
+    return RETURN_SUCCESS;\r
 }\r
 \r
 RETURN_STATUS\r
@@ -169,6 +180,11 @@ SemihostFileRemove (
   SEMIHOST_FILE_REMOVE_BLOCK  RemoveBlock;\r
   UINT32                      Result;\r
 \r
+  // Remove any leading separator (e.g.: '\'). EFI Shell adds one.\r
+  if (*FileName == '\\') {\r
+    FileName++;\r
+  }\r
+\r
   RemoveBlock.FileName    = FileName;\r
   RemoveBlock.NameLength  = AsciiStrLen(FileName);\r
 \r
@@ -204,7 +220,7 @@ SemihostWriteString (
 {\r
   Semihost_SYS_WRITE0(String);\r
 }\r
-  \r
+\r
 UINT32\r
 SemihostSystem (\r
   IN CHAR8 *CommandLine\r