]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/BaseLib.h
MdePkg/BaseLib: Add more comments for safe string functions.
[mirror_edk2.git] / MdePkg / Include / Library / BaseLib.h
index bd3f9cfc601fefbdbe6e69423859c6033a504e48..6f6bd8515766d146c9f6863f38f88074eef0330b 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Provides string functions, linked list functions, math functions, synchronization\r
-  functions, and CPU architecture-specific functions.\r
+  functions, file path functions, and CPU architecture-specific functions.\r
 \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 Portions copyright (c) 2008 - 2009, Apple Inc. 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
@@ -187,6 +187,8 @@ typedef struct {
 /**\r
   Returns the length of a Null-terminated Unicode string.\r
 \r
+  This function is similar as strlen_s defined in C11.\r
+\r
   If String is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
   @param  String   A pointer to a Null-terminated Unicode string.\r
@@ -209,8 +211,13 @@ StrnLenS (
   Copies the string pointed to by Source (including the terminating null char)\r
   to the array pointed to by Destination.\r
 \r
+  This function is similar as strcpy_s defined in C11.\r
+\r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Unicode string.\r
   @param  DestMax                  The maximum number of Destination Unicode\r
@@ -240,8 +247,13 @@ StrCpyS (
   Source to the array pointed to by Destination. If no null char is copied from\r
   Source, then Destination[Length] is always set to null.\r
 \r
+  This function is similar as strncpy_s defined in C11.\r
+\r
   If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Unicode string.\r
   @param  DestMax                  The maximum number of Destination Unicode\r
@@ -273,8 +285,13 @@ StrnCpyS (
   Appends a copy of the string pointed to by Source (including the terminating\r
   null char) to the end of the string pointed to by Destination.\r
 \r
+  This function is similar as strcat_s defined in C11.\r
+\r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Unicode string.\r
   @param  DestMax                  The maximum number of Destination Unicode\r
@@ -308,8 +325,13 @@ StrCatS (
   copied from Source, then Destination[StrLen(Destination) + Length] is always\r
   set to null.\r
 \r
+  This function is similar as strncat_s defined in C11.\r
+\r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
-  If and Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Unicode string.\r
   @param  DestMax                  The maximum number of Destination Unicode\r
@@ -342,6 +364,8 @@ StrnCatS (
 /**\r
   Returns the length of a Null-terminated Ascii string.\r
 \r
+  This function is similar as strlen_s defined in C11.\r
+\r
   @param  String   A pointer to a Null-terminated Ascii string.\r
   @param  MaxSize  The maximum number of Destination Ascii\r
                    char, including terminating null char.\r
@@ -362,6 +386,12 @@ AsciiStrnLenS (
   Copies the string pointed to by Source (including the terminating null char)\r
   to the array pointed to by Destination.\r
 \r
+  This function is similar as strcpy_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
   @param  DestMax                  The maximum number of Destination Ascii\r
                                    char, including terminating null char.\r
@@ -390,6 +420,12 @@ AsciiStrCpyS (
   Source to the array pointed to by Destination. If no null char is copied from\r
   Source, then Destination[Length] is always set to null.\r
 \r
+  This function is similar as strncpy_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
   @param  DestMax                  The maximum number of Destination Ascii\r
                                    char, including terminating null char.\r
@@ -420,6 +456,12 @@ AsciiStrnCpyS (
   Appends a copy of the string pointed to by Source (including the terminating\r
   null char) to the end of the string pointed to by Destination.\r
 \r
+  This function is similar as strcat_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
   @param  DestMax                  The maximum number of Destination Ascii\r
                                    char, including terminating null char.\r
@@ -452,6 +494,12 @@ AsciiStrCatS (
   copied from Source, then Destination[StrLen(Destination) + Length] is always\r
   set to null.\r
 \r
+  This function is similar as strncat_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
   @param  DestMax                  The maximum number of Destination Ascii\r
                                    char, including terminating null char.\r
@@ -484,7 +532,7 @@ AsciiStrnCatS (
 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
   string and returns the new Unicode string.\r
@@ -517,7 +565,7 @@ StrCpy (
 \r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Copies up to a specified length from one Null-terminated Unicode string to \r
   another Null-terminated Unicode string and returns the new Unicode string.\r
@@ -686,7 +734,7 @@ StrnCmp (
 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Concatenates one Null-terminated Unicode string to another Null-terminated\r
   Unicode string, and returns the concatenated Unicode string.\r
@@ -728,7 +776,7 @@ StrCat (
 \r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Concatenates up to a specified length one Null-terminated Unicode to the end \r
   of another Null-terminated Unicode string, and returns the concatenated \r
@@ -1016,7 +1064,7 @@ UnicodeStrToAsciiStr (
 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Copies one Null-terminated ASCII string to another Null-terminated ASCII\r
   string and returns the new ASCII string.\r
@@ -1047,7 +1095,7 @@ AsciiStrCpy (
 \r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Copies up to a specified length one Null-terminated ASCII string to another \r
   Null-terminated ASCII string and returns the new ASCII string.\r
@@ -1245,7 +1293,7 @@ AsciiStrnCmp (
 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Concatenates one Null-terminated ASCII string to another Null-terminated\r
   ASCII string, and returns the concatenated ASCII string.\r
@@ -1282,7 +1330,7 @@ AsciiStrCat (
 \r
 \r
 /**\r
-  [ATTENTION] This function will be deprecated for security reason.\r
+  [ATTENTION] This function is deprecated for security reason.\r
 \r
   Concatenates up to a specified length one Null-terminated ASCII string to \r
   the end of another Null-terminated ASCII string, and returns the \r
@@ -1591,6 +1639,43 @@ BcdToDecimal8 (
   IN      UINT8                     Value\r
   );\r
 \r
+//\r
+//  File Path Manipulation Functions\r
+//\r
+\r
+/**\r
+  Removes the last directory or file entry in a path by changing the last\r
+  L'\' to a CHAR_NULL.\r
+\r
+  @param[in, out] Path    The pointer to the path to modify.\r
+\r
+  @retval FALSE     Nothing was found to remove.\r
+  @retval TRUE      A directory or file was removed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PathRemoveLastItem(\r
+  IN OUT CHAR16 *Path\r
+  );\r
+\r
+/**\r
+  Function to clean up paths.\r
+    - Single periods in the path are removed.\r
+    - Double periods in the path are removed along with a single parent directory.\r
+    - Forward slashes L'/' are converted to backward slashes L'\'.\r
+\r
+  This will be done inline and the existing buffer may be larger than required\r
+  upon completion.\r
+\r
+  @param[in] Path       The pointer to the string containing the path.\r
+\r
+  @return       Returns Path, otherwise returns NULL to indicate that an error has occured.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+PathCleanUpDirectories(\r
+  IN CHAR16 *Path\r
+  );\r
 \r
 //\r
 // Linked List Functions and Macros\r
@@ -7598,6 +7683,57 @@ AsmPrepareAndThunk16 (
   IN OUT  THUNK_CONTEXT             *ThunkContext\r
   );\r
 \r
+/**\r
+  Generates a 16-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+ **/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand16 (\r
+  OUT     UINT16                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 32-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand32 (\r
+  OUT     UINT32                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 64-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand64  (\r
+  OUT     UINT64                    *Rand\r
+  );\r
+\r
 #endif\r
 #endif\r
 \r