Revision: 14891
          http://sourceforge.net/p/edk2/code/14891
Author:   jcarsey
Date:     2013-11-22 21:15:19 +0000 (Fri, 22 Nov 2013)
Log Message:
-----------
ShellPkg: Remove trailing \r\n when redirect to env variable (EX: use ">v")

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <[email protected]>
Reviewed-by: Jaben Carsey <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/FileHandleWrappers.c

Modified: trunk/edk2/ShellPkg/Application/Shell/FileHandleWrappers.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/FileHandleWrappers.c  2013-11-22 
08:33:17 UTC (rev 14890)
+++ trunk/edk2/ShellPkg/Application/Shell/FileHandleWrappers.c  2013-11-22 
21:15:19 UTC (rev 14891)
@@ -3,6 +3,7 @@
   StdIn, StdOut, StdErr, etc...).
 
   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -950,8 +951,48 @@
   IN EFI_FILE_PROTOCOL *This
   )
 {
+  VOID*       NewBuffer;
+  UINTN       NewSize;
+  EFI_STATUS  Status;
+
+  //
+  // Most if not all UEFI commands will have an '\r\n' at the end of any 
output. 
+  // Since the output was redirected to a variable, it does not make sense to 
+  // keep this.  So, before closing, strip the trailing '\r\n' from the 
variable
+  // if it exists.
+  //
+  NewBuffer   = NULL;
+  NewSize     = 0;
+
+  Status = 
SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, 
&NewSize, NewBuffer);
+  if (Status == EFI_BUFFER_TOO_SMALL) {
+    NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16));
+    if (NewBuffer == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }  
+    Status = 
SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, 
&NewSize, NewBuffer);
+  }
+  
+  if (!EFI_ERROR(Status)) {
+    
+    if (StrSize(NewBuffer) > 6)
+    {
+      if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED) 
+           && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == 
CHAR_CARRIAGE_RETURN)) {
+        ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL;   
+      }
+    
+      if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name)) {
+        Status = 
SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, 
StrSize(NewBuffer), NewBuffer);
+      } else {
+        Status = 
SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, 
StrSize(NewBuffer), NewBuffer);
+      }
+    }
+  } 
+  
+  SHELL_FREE_NON_NULL(NewBuffer);
   FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);
-  return (EFI_SUCCESS);
+  return (Status);
 }
 
 /**

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to