]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / ShellPkg / Library / UefiFileHandleLib / UefiFileHandleLib.c
index fd8b7bbaec1d14bd4b25ae60c084dc901b0a0d37..0bee8e38992d5b601a163f2641be02c923648e54 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to EFI_FILE_HANDLE functionality.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2006 - 2012, 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
@@ -101,20 +101,20 @@ FileHandleGetInfo (
 \r
   @param[in]  FileInfo          The information to set.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
+  @retval EFI_SUCCESS           The information was set.\r
   @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
   @retval EFI_UNSUPPORTED       The FileHandle does not support FileInfo.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 FileHandleSetInfo (\r
-  IN EFI_FILE_HANDLE           FileHandle,\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
   IN CONST EFI_FILE_INFO        *FileInfo\r
   )\r
 {\r
@@ -198,14 +198,14 @@ FileHandleRead(
                               the number of bytes written.\r
   @param Buffer               the buffer containing data to write is stored.\r
 \r
- @retval EFI_SUCCESS           Data was written.\r
- @retval EFI_UNSUPPORTED           Writes to an open directory are not supported.\r
- @retval EFI_NO_MEDIA          The device has no media.\r
- @retval EFI_DEVICE_ERROR          The device reported an error.\r
- @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
- @retval EFI_WRITE_PROTECTED   The device is write-protected.\r
- @retval EFI_ACCESS_DENIED       The file was open for read only.\r
- @retval EFI_VOLUME_FULL           The volume is full.\r
+ @retval EFI_SUCCESS          Data was written.\r
+ @retval EFI_UNSUPPORTED      Writes to an open directory are not supported.\r
+ @retval EFI_NO_MEDIA         The device has no media.\r
+ @retval EFI_DEVICE_ERROR     The device reported an error.\r
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+ @retval EFI_WRITE_PROTECTED  The device is write-protected.\r
+ @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+ @retval EFI_VOLUME_FULL      The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -266,12 +266,12 @@ FileHandleClose (
   @retval EFI_SUCCESS           the file was closed sucessfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                 deleted\r
-  @retval INVALID_PARAMETER            One of the parameters has an invalid value.\r
+  @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 FileHandleDelete (\r
-  IN EFI_FILE_HANDLE           FileHandle\r
+  IN EFI_FILE_HANDLE    FileHandle\r
   )\r
 {\r
   EFI_STATUS Status;\r
@@ -308,8 +308,8 @@ FileHandleDelete (
 EFI_STATUS\r
 EFIAPI\r
 FileHandleSetPosition (\r
-  IN EFI_FILE_HANDLE           FileHandle,\r
-  IN UINT64            Position\r
+  IN EFI_FILE_HANDLE    FileHandle,\r
+  IN UINT64             Position\r
   )\r
 {\r
   //\r
@@ -441,15 +441,19 @@ FileHandleIsDirectory (
   return (EFI_SUCCESS);\r
 }\r
 \r
-/**\r
-  Retrieves the first file from a directory\r
+/** Retrieve first entry from a directory.\r
+\r
+  This function takes an open directory handle and gets information from the\r
+  first entry in the directory.  A buffer is allocated to contain\r
+  the information and a pointer to the buffer is returned in *Buffer.  The\r
+  caller can use FileHandleFindNextFile() to get subsequent directory entries.\r
 \r
-  This function opens a directory and gets the first file's info in the\r
-  directory. Caller can use FileHandleFindNextFile() to get other files.  When\r
-  complete the caller is responsible for calling FreePool() on Buffer.\r
+  The buffer will be freed by FileHandleFindNextFile() when the last directory\r
+  entry is read.  Otherwise, the caller must free the buffer, using FreePool,\r
+  when finished with it.\r
 \r
-  @param DirHandle              The file handle of the directory to search\r
-  @param Buffer                 Pointer to buffer for file's information\r
+  @param[in]  DirHandle         The file handle of the directory to search.\r
+  @param[out] Buffer            The pointer to pointer to buffer for file's information.\r
 \r
   @retval EFI_SUCCESS           Found the first file.\r
   @retval EFI_NOT_FOUND         Cannot find the directory.\r
@@ -512,19 +516,19 @@ FileHandleFindFirstFile (
   }\r
   return (EFI_SUCCESS);\r
 }\r
-/**\r
-  Retrieves the next file in a directory.\r
 \r
-  To use this function, caller must call the FileHandleFindFirstFile() to get the\r
-  first file, and then use this function get other files. This function can be\r
-  called for several times to get each file's information in the directory. If\r
-  the call of FileHandleFindNextFile() got the last file in the directory, the next\r
-  call of this function has no file to get. *NoFile will be set to TRUE and the\r
-  Buffer memory will be automatically freed.\r
+/** Retrieve next entries from a directory.\r
+\r
+  To use this function, the caller must first call the FileHandleFindFirstFile()\r
+  function to get the first directory entry.  Subsequent directory entries are\r
+  retrieved by using the FileHandleFindNextFile() function.  This function can\r
+  be called several times to get each entry from the directory.  If the call of\r
+  FileHandleFindNextFile() retrieved the last directory entry, the next call of\r
+  this function will set *NoFile to TRUE and free the buffer.\r
 \r
-  @param DirHandle              the file handle of the directory\r
-  @param Buffer                                    pointer to buffer for file's information\r
-  @param NoFile                                    pointer to boolean when last file is found\r
+  @param[in]  DirHandle         The file handle of the directory.\r
+  @param[out] Buffer            The pointer to buffer for file's information.\r
+  @param[out] NoFile            The pointer to boolean when last file is found.\r
 \r
   @retval EFI_SUCCESS           Found the next file, or reached last file\r
   @retval EFI_NO_MEDIA          The device has no media.\r
@@ -534,9 +538,9 @@ FileHandleFindFirstFile (
 EFI_STATUS\r
 EFIAPI\r
 FileHandleFindNextFile(\r
-  IN EFI_FILE_HANDLE             DirHandle,\r
-  OUT EFI_FILE_INFO              *Buffer,\r
-  OUT BOOLEAN                    *NoFile\r
+  IN EFI_FILE_HANDLE          DirHandle,\r
+  OUT EFI_FILE_INFO          *Buffer,\r
+  OUT BOOLEAN                *NoFile\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -698,8 +702,8 @@ FileHandleSetSize (
   if Destination's current length (including NULL terminator) is already more then\r
   CurrentSize, then ASSERT()\r
 \r
-  @param[in,out] Destination   The String to append onto\r
-  @param[in,out] CurrentSize   on call the number of bytes in Destination.  On\r
+  @param[in, out] Destination   The String to append onto\r
+  @param[in, out] CurrentSize   on call the number of bytes in Destination.  On\r
                                 return possibly the new size (still in bytes).  if NULL\r
                                 then allocate whatever is needed.\r
   @param[in]      Source        The String to append from\r
@@ -765,6 +769,9 @@ StrnCatGrowLeft (
   } else {\r
     *Destination = AllocateZeroPool(Count+sizeof(CHAR16));\r
   }\r
+  if (*Destination == NULL) {\r
+    return NULL;\r
+  }\r
 \r
   CopySize = StrSize(*Destination);\r
   CopyMem((*Destination)+((Count-2)/sizeof(CHAR16)), *Destination, CopySize);\r
@@ -879,8 +886,8 @@ FileHandleGetFileName (
   If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
   maintained and not changed for all operations with the same file.\r
 \r
-  @param[in]      Handle        FileHandle to read from.\r
-  @param[in,out]  Ascii         Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
+  @param[in]       Handle        FileHandle to read from.\r
+  @param[in, out]  Ascii         Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
 \r
   @return                       The line of text from the file.\r
 \r
@@ -919,13 +926,13 @@ FileHandleReturnLine(
   If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
   maintained and not changed for all operations with the same file.\r
 \r
-  @param[in]      Handle        FileHandle to read from\r
-  @param[in,out]  Buffer        pointer to buffer to read into\r
-  @param[in,out]  Size          pointer to number of bytes in buffer\r
-  @param[in]      Truncate      if TRUE then allows for truncation of the line to fit.\r
-                                if FALSE will reset the position to the begining of the\r
-                                line if the buffer is not large enough.\r
-  @param[in,out]  Ascii         Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
+  @param[in]       Handle        FileHandle to read from\r
+  @param[in, out]  Buffer        pointer to buffer to read into\r
+  @param[in, out]  Size          pointer to number of bytes in buffer\r
+  @param[in]       Truncate      if TRUE then allows for truncation of the line to fit.\r
+                                 if FALSE will reset the position to the begining of the\r
+                                 line if the buffer is not large enough.\r
+  @param[in, out]  Ascii         Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
 \r
   @retval EFI_SUCCESS           the operation was sucessful.  the line is stored in\r
                                 Buffer.\r
@@ -1082,8 +1089,6 @@ FileHandlePrintLine(
   CHAR16            *Buffer;\r
   EFI_STATUS        Status;\r
 \r
-  VA_START (Marker, Format);\r
-\r
   //\r
   // Get a buffer to print into\r
   //\r
@@ -1093,7 +1098,9 @@ FileHandlePrintLine(
   //\r
   // Print into our buffer\r
   //\r
+  VA_START (Marker, Format);\r
   UnicodeVSPrint (Buffer, PcdGet16 (PcdShellPrintBufferSize), Format, Marker);\r
+  VA_END (Marker);\r
 \r
   //\r
   // Print buffer into file\r