Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Ericsson AB 3 : : */ 4 : : 5 : : #include <errno.h> 6 : : #include <stdbool.h> 7 : : #include <stdint.h> 8 : : #include <sys/types.h> 9 : : 10 : : #include <eal_export.h> 11 : : #include "rte_bitset.h" 12 : : 13 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_bitset_to_str, 24.11) 14 : : ssize_t 15 : 4 : rte_bitset_to_str(const uint64_t *bitset, size_t num_bits, char *buf, size_t capacity) 16 : : { 17 : : size_t i; 18 : : 19 [ + + ]: 4 : if (capacity < (num_bits + 1)) 20 : : return -EINVAL; 21 : : 22 [ + + ]: 105 : for (i = 0; i < num_bits; i++) { 23 : : bool value; 24 : : 25 [ + + ]: 102 : value = rte_bitset_test(bitset, num_bits - 1 - i); 26 [ + + ]: 201 : buf[i] = value ? '1' : '0'; 27 : : } 28 : : 29 : 3 : buf[num_bits] = '\0'; 30 : : 31 : 3 : return num_bits + 1; 32 : : }