xref: /dpdk/lib/eal/common/rte_bitset.c (revision 99a1197647d803e43a676622396ffddf6bf93b62)
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 rte_bitset_to_str(const uint64_t *bitset, size_t num_bits, char *buf, size_t capacity)
14 {
15 	size_t i;
16 
17 	if (capacity < (num_bits + 1))
18 		return -EINVAL;
19 
20 	for (i = 0; i < num_bits; i++) {
21 		bool value;
22 
23 		value = rte_bitset_test(bitset, num_bits - 1 - i);
24 		buf[i] = value ? '1' : '0';
25 	}
26 
27 	buf[num_bits] = '\0';
28 
29 	return num_bits + 1;
30 }
31