From 6126bb65139030a1c3e89342b7bab726d77af966 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 9 Oct 2023 17:58:28 +0200 Subject: [PATCH] Added a find_selector function to the plugin SDK --- src_plugin_sdk/utils.c | 28 ++++++++++++++++++++++++++++ src_plugin_sdk/utils.h | 27 +++++++++++++++++++++++++++ tools/build_sdk.py | 2 ++ 3 files changed, 57 insertions(+) create mode 100644 src_plugin_sdk/utils.c create mode 100644 src_plugin_sdk/utils.h diff --git a/src_plugin_sdk/utils.c b/src_plugin_sdk/utils.c new file mode 100644 index 000000000..059430efd --- /dev/null +++ b/src_plugin_sdk/utils.c @@ -0,0 +1,28 @@ +/***************************************************************************** + * Ledger Plugin SDK + * (c) 2023 Ledger SAS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#include "utils.h" + +bool find_selector(uint32_t selector, const uint32_t *array, size_t size, size_t *idx) { + for (size_t i = 0; i < size; ++i) { + if (selector == array[i]) { + if (idx != NULL) *idx = i; + return true; + } + } + return false; +} diff --git a/src_plugin_sdk/utils.h b/src_plugin_sdk/utils.h new file mode 100644 index 000000000..e2816f91d --- /dev/null +++ b/src_plugin_sdk/utils.h @@ -0,0 +1,27 @@ +/***************************************************************************** + * Ledger Plugin SDK + * (c) 2023 Ledger SAS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#ifndef UTILS_H_ +#define UTILS_H_ + +#include +#include +#include + +bool find_selector(uint32_t selector, const uint32_t *array, size_t size, size_t *idx); + +#endif // UTILS_H_ diff --git a/tools/build_sdk.py b/tools/build_sdk.py index bc3af58cc..225ef5d39 100755 --- a/tools/build_sdk.py +++ b/tools/build_sdk.py @@ -210,6 +210,8 @@ def merge_c_files(sources, nodes_to_extract): files_to_copy = [ "main.c", + "utils.c", + "utils.h", ] for file in files_to_copy: