diff options
author | Joursoir <chat@joursoir.net> | 2021-11-17 18:14:10 +0300 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-11-17 18:14:10 +0300 |
commit | dc3f1f5224c86c3d99f6c401accadd2769552038 (patch) | |
tree | fe50067a9890c23824ed47be9f8aa2c2555a6d31 | |
parent | 2c4ace2c2cf853c85d9b32d42e8bae39d88a7355 (diff) | |
download | ufm-dc3f1f5224c86c3d99f6c401accadd2769552038.tar.gz ufm-dc3f1f5224c86c3d99f6c401accadd2769552038.tar.bz2 ufm-dc3f1f5224c86c3d99f6c401accadd2769552038.zip |
dir: make scandir()
-rw-r--r-- | Library/UefiShellUfmCommandLib/dir.c | 26 | ||||
-rw-r--r-- | Library/UefiShellUfmCommandLib/dir.h | 14 |
2 files changed, 40 insertions, 0 deletions
diff --git a/Library/UefiShellUfmCommandLib/dir.c b/Library/UefiShellUfmCommandLib/dir.c index 12bc13b..8e3a083 100644 --- a/Library/UefiShellUfmCommandLib/dir.c +++ b/Library/UefiShellUfmCommandLib/dir.c @@ -62,3 +62,29 @@ VOID dirl_release(struct dir_list *dl) FreePool(dl); } + +struct dir_list *scandir(CONST CHAR16 *search_path, CONST CHAR16 *wildcard, + CONST UINT64 attr) +{ + UINTN i, path_size = 0; + CHAR16 *path = NULL; + struct dir_list *list; + + path = StrnCatGrow(&path, &path_size, search_path, 0); + if(!path) + return NULL; + + i = StrLen(path) - 1; + if(path[i] != L'\\' && path[i] != L'/') + path = StrnCatGrow(&path, &path_size, L"\\", 0); + + path = StrnCatGrow(&path, &path_size, wildcard, 0); + if(!path) + return NULL; + + PathCleanUpDirectories(path); + list = dirl_alloc(path, attr); + + SHELL_FREE_NON_NULL(path); + return list; +} diff --git a/Library/UefiShellUfmCommandLib/dir.h b/Library/UefiShellUfmCommandLib/dir.h index be560ad..94ad601 100644 --- a/Library/UefiShellUfmCommandLib/dir.h +++ b/Library/UefiShellUfmCommandLib/dir.h @@ -27,4 +27,18 @@ struct dir_list *dirl_alloc(CHAR16 *search_path, CONST UINT64 attr); */ VOID dirl_release(struct dir_list *dl); +/* + * Opens a directory and gets all its matching entries. This function + * supports wildcards and will process '?' and '*' as such + * P.S: it's frontend function of dirl_alloc() + * + * search_path: the pointer to path string + * wildcard: the pointer to wildcard string + * attr: required file attributes + * + * return: A pointer to the allocated structure or NULL if allocation fails +*/ +struct dir_list *scandir(CONST CHAR16 *search_path, CONST CHAR16 *wildcard, + CONST UINT64 attr); + #endif /* UFM_DIR_H */ |