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 "rte_bitset.h" 11 : : 12 : : ssize_t 13 : 4 : rte_bitset_to_str(const uint64_t *bitset, size_t num_bits, char *buf, size_t capacity) 14 : : { 15 : : size_t i; 16 : : 17 [ + + ]: 4 : if (capacity < (num_bits + 1)) 18 : : return -EINVAL; 19 : : 20 [ + + ]: 105 : for (i = 0; i < num_bits; i++) { 21 : : bool value; 22 : : 23 [ + + ]: 102 : value = rte_bitset_test(bitset, num_bits - 1 - i); 24 [ + + ]: 201 : buf[i] = value ? '1' : '0'; 25 : : } 26 : : 27 : 3 : buf[num_bits] = '\0'; 28 : : 29 : 3 : return num_bits + 1; 30 : : }