]> code.delx.au - refind/blobdiff - refind/lib.c
Better reporting of SIP problems; minor code cleanup.
[refind] / refind / lib.c
index 961e89ddd447e98c5c3d139ce07b87ce7dad0b07..3a75cdfdcacb62cb8746ed225184c7c86e05c73c 100644 (file)
  * Modifications copyright (c) 2012-2015 Roderick W. Smith
  *
  * Modifications distributed under the terms of the GNU General Public
- * License (GPL) version 3 (GPLv3), a copy of which must be distributed
- * with this source code or binaries made from it.
+ * License (GPL) version 3 (GPLv3), or (at your option) any later version.
  *
  */
+/*
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #include "global.h"
 #include "lib.h"
@@ -2018,6 +2031,23 @@ BOOLEAN EjectMedia(VOID) {
     return (Ejected > 0);
 } // VOID EjectMedia()
 
+// Returns TRUE if *Input contains nothing but valid hexadecimal characters,
+// FALSE otherwise. Note that a leading "0x" is NOT acceptable in the input!
+BOOLEAN IsValidHex(CHAR16 *Input) {
+    BOOLEAN IsHex = TRUE;
+    UINTN i = 0;
+
+    while ((Input[i] != L'\0') && IsHex) {
+        if (!(((Input[i] >= L'0') && (Input[i] <= L'9')) ||
+              ((Input[i] >= L'A') && (Input[i] <= L'F')) ||
+              ((Input[i] >= L'a') && (Input[i] <= L'f')))) {
+                IsHex = FALSE;
+        }
+        i++;
+    } // while
+    return IsHex;
+} // BOOLEAN IsValidHex()
+
 // Converts consecutive characters in the input string into a
 // number, interpreting the string as a hexadecimal number, starting
 // at the specified position and continuing for the specified number
@@ -2128,3 +2158,13 @@ BOOLEAN GuidsAreEqual(EFI_GUID *Guid1, EFI_GUID *Guid2) {
     return (CompareMem(Guid1, Guid2, 16) == 0);
 } // BOOLEAN GuidsAreEqual()
 
+// Erase linked-list of UINT32 values....
+VOID EraseUint32List(UINT32_LIST **TheList) {
+    UINT32_LIST *NextItem;
+
+    while (*TheList) {
+        NextItem = (*TheList)->Next;
+        FreePool(*TheList);
+        *TheList = NextItem;
+    } // while
+} // EraseUin32List()