0
NEWオプションをUCI設定ファイルの特定のセクションに追加するにはどうすればよいですか? C APIを使用してプログラムで達成したいと思います。誰かがここに例を挙げることはできますか?UCIのC APIを使用して特定のセクションにオプションを追加
NEWオプションをUCI設定ファイルの特定のセクションに追加するにはどうすればよいですか? C APIを使用してプログラムで達成したいと思います。誰かがここに例を挙げることはできますか?UCIのC APIを使用して特定のセクションにオプションを追加
#include <uci.h>
#include <stdio.h>
int main() {
uci_context* ctx = uci_alloc_context();
if (!ctx) {
printf("failed to alloc uci ctx\n");
return 1;
}
uci_ptr config;
char section_name[] = "your_package.your_section";
if (uci_lookup_ptr(ctx, &config, section_name, true) != UCI_OK || !config.s) {
printf("failed to find the specified section\n");
return 1;
}
config.option = "new_option_name";
config.value = "new_option_value";
if (uci_set(ctx, &config) != UCI_OK) {
printf("failed to set new option\n");
return 1;
}
if (uci_commit(ctx, &config.p, false) != UCI_OK) {
printf("failed to commit changes\n");
return 1;
}
return 0;
}