summaryrefslogtreecommitdiff
path: root/lib/shell.c
diff options
context:
space:
mode:
authorSteve Langasek <steve.langasek@canonical.com>2014-10-06 17:17:33 -0700
committerSteve Langasek <steve.langasek@canonical.com>2014-10-06 17:17:33 -0700
commit59945b252e76a601fc6bbf43fb49f8a8f0d0c9a9 (patch)
tree70e8a684bf6b3480abf1504e7befb1f8f955d962 /lib/shell.c
parent5fc0e7f624b64f40d5d4694e35f8c967a7317902 (diff)
parent72bb39c0237f8bcc3afa8b623e8b097eec6d69cd (diff)
downloadefi-boot-shim-59945b252e76a601fc6bbf43fb49f8a8f0d0c9a9.tar.gz
efi-boot-shim-59945b252e76a601fc6bbf43fb49f8a8f0d0c9a9.zip
Merge upstream version 0.7
Diffstat (limited to 'lib/shell.c')
-rw-r--r--lib/shell.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/shell.c b/lib/shell.c
new file mode 100644
index 00000000..51de4e0d
--- /dev/null
+++ b/lib/shell.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2012 <James.Bottomley@HansenPartnership.com>
+ *
+ * see COPYING file
+ *
+ * misc shell helper functions
+ */
+#include <efi.h>
+#include <efilib.h>
+
+#include <shell.h>
+
+EFI_STATUS
+argsplit(EFI_HANDLE image, int *argc, CHAR16*** ARGV)
+{
+ int i, count = 1;
+ EFI_STATUS status;
+ EFI_LOADED_IMAGE *info;
+ CHAR16 *start;
+
+ *argc = 0;
+
+ status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &LoadedImageProtocol, (VOID **) &info);
+ if (EFI_ERROR(status)) {
+ Print(L"Failed to get arguments\n");
+ return status;
+ }
+
+ for (i = 0; i < info->LoadOptionsSize; i += 2) {
+ CHAR16 *c = (CHAR16 *)(info->LoadOptions + i);
+ if (*c == L' ' && *(c+1) != '\0') {
+ (*argc)++;
+ }
+ }
+
+ (*argc)++; /* we counted spaces, so add one for initial */
+
+ *ARGV = AllocatePool(*argc * sizeof(*ARGV));
+ if (!*ARGV) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ (*ARGV)[0] = (CHAR16 *)info->LoadOptions;
+ for (i = 0; i < info->LoadOptionsSize; i += 2) {
+ CHAR16 *c = (CHAR16 *)(info->LoadOptions + i);
+ if (*c == L' ') {
+ *c = L'\0';
+ if (*(c + 1) == '\0')
+ /* strip trailing space */
+ break;
+ start = c + 1;
+ (*ARGV)[count++] = start;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+