CHAR16 *RetVal;\r
CHAR16 *TestPath;\r
CONST CHAR16 *Walker;\r
+ UINTN Size;\r
\r
RetVal = NULL;\r
\r
Path = ShellGetEnvironmentVariable(L"cwd");\r
if (Path != NULL) {\r
- TestPath = AllocateZeroPool((StrSize(Path) + StrSize(FileName)));\r
+ Size = StrSize(Path);\r
+ Size += StrSize(FileName);\r
+ TestPath = AllocateZeroPool(Size);\r
StrCpy(TestPath, Path);\r
StrCat(TestPath, FileName);\r
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
}\r
Path = ShellGetEnvironmentVariable(L"path");\r
if (Path != NULL) {\r
- TestPath = AllocateZeroPool((StrSize(Path)+StrSize(FileName)));\r
+ Size = StrSize(Path);\r
+ Size += StrSize(FileName);\r
+ TestPath = AllocateZeroPool(Size);\r
Walker = (CHAR16*)Path; \r
do {\r
CopyMem(TestPath, Walker, StrSize(Walker));\r
return (mTotalParameterCount);\r
}\r
\r
+/**\r
+ Determins if a parameter is duplicated.\r
+\r
+ If Param is not NULL then it will point to a callee allocated string buffer \r
+ with the parameter value if a duplicate is found.\r
+\r
+ If CheckPackage is NULL, then ASSERT.\r
+\r
+ @param[in] CheckPackage The package of parsed command line arguments.\r
+ @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r
+\r
+ @retval EFI_SUCCESS No parameters were duplicated.\r
+ @retval EFI_DEVICE_ERROR A duplicate was found.\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCommandLineCheckDuplicate (\r
+ IN CONST LIST_ENTRY *CheckPackage,\r
+ OUT CHAR16 **Param\r
+ )\r
+{\r
+ LIST_ENTRY *Node1;\r
+ LIST_ENTRY *Node2;\r
+ \r
+ ASSERT(CheckPackage != NULL);\r
+\r
+ for ( Node1 = GetFirstNode(CheckPackage) \r
+ ; !IsNull (CheckPackage, Node1) \r
+ ; Node1 = GetNextNode(CheckPackage, Node1) \r
+ ){\r
+ for ( Node2 = GetNextNode(CheckPackage, Node1) \r
+ ; !IsNull (CheckPackage, Node2) \r
+ ; Node2 = GetNextNode(CheckPackage, Node2) \r
+ ){\r
+ if (StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {\r
+ if (Param != NULL) {\r
+ *Param = NULL;\r
+ *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);\r
+ }\r
+ return (EFI_DEVICE_ERROR);\r
+ }\r
+ }\r
+ }\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
/**\r
This is a find and replace function. it will return the NewString as a copy of \r
SourceString with each instance of FindTarget replaced with ReplaceWith.\r
return (EFI_NOT_FOUND);\r
}\r
\r
+/**\r
+ Function to determine if a given filename represents a file.\r
+\r
+ @param[in] Name Path to file to test.\r
+\r
+ @retval EFI_SUCCESS The Path represents a file.\r
+ @retval EFI_NOT_FOUND The Path does not represent a file.\r
+ @retval other The path failed to open.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellIsFile(\r
+ IN CONST CHAR16 *Name\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_FILE_HANDLE Handle;\r
+\r
+ Handle = NULL;\r
+\r
+ Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+\r
+ if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
+ ShellCloseFile(&Handle);\r
+ return (EFI_SUCCESS);\r
+ }\r
+ ShellCloseFile(&Handle);\r
+ return (EFI_NOT_FOUND);\r
+}\r
+\r
/**\r
Function to determine whether a string is decimal or hex representation of a number \r
and return the number converted from the string.\r