/
phprus
/
github_dpdk
Обзор
Документация
Войти
/
phprus
/
github_dpdk
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/cmdline/cmdline_parse_bool.c
80 строк
2 KB
Bruce Richardson
cmdline: add explicit help function for bool type
18 май 2026, 13:28
18 май 2026, 13:28
85a4a1e
Код
Авторство
О чём код?
/* SPDX-License-Identifier: BSD-3-Clause * Copyright (c) 2023 NVIDIA Corporation & Affiliates */ #include <stdio.h> #include <stdint.h> #include <inttypes.h> #include <string.h> #include <eal_export.h> #include <rte_string_fns.h> #include <stdlib.h> #include "cmdline_parse.h" #include "cmdline_parse_bool.h" static int cmdline_get_help_bool(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size); RTE_EXPORT_EXPERIMENTAL_SYMBOL(cmdline_token_bool_ops, 25.03) struct cmdline_token_ops cmdline_token_bool_ops = { .parse = cmdline_parse_bool, .complete_get_nb = NULL, .complete_get_elt = NULL, .get_help = cmdline_get_help_bool, }; static cmdline_parse_token_string_t cmd_parse_token_bool = { { &cmdline_token_string_ops, 0 }, { "on#off" } }; /* get help for bool token */ static int cmdline_get_help_bool(__rte_unused cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size) { if (dstbuf == NULL || size == 0) return -1; strlcpy(dstbuf, "on|off", size); return 0; } /* parse string to bool */ int cmdline_parse_bool(__rte_unused cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res, unsigned int ressize) { cmdline_fixed_string_t on_off = {0}; uint8_t val; if (!srcbuf || !*srcbuf) return -1; if (res != NULL && ressize < sizeof(uint8_t)) return -1; if (cmdline_token_string_ops.parse (&cmd_parse_token_bool.hdr, srcbuf, on_off, sizeof(on_off)) < 0) return -1; if (strcmp((char *)on_off, "on") == 0) val = 1; else if (strcmp((char *)on_off, "off") == 0) val = 0; else return -1; if (res != NULL) *(uint8_t *)res = val; return strlen(on_off); }