/* The return value is the number of characters which would be generated for the given input, excluding the trailing '\0', as per ISO C99.  */
int bitmap_scnlistprintf(char *buf, unsigned int buflen, const unsigned long *maskp, int nmaskbits)
/* The return value is the number of characters which would be generated for the given input, excluding the trailing '\0', as per ISO C99.  */
int bitmap_scnlistprintf(char *buf, unsigned int buflen, const unsigned long *maskp, int nmaskbits)
{
	int len = 0;
	int cur, rbot, rtop;
	if (buflen == 0)
		return 0;
	buf[0] = 0;
	rbot = cur = find_first_bit(maskp, nmaskbits);
	while (cur < nmaskbits) {
		rtop = cur;
		cur = find_next_bit(maskp, nmaskbits, cur+1);
		if (cur >= nmaskbits || cur > rtop + 1) {
			len = bscnl_emit(buf, buflen, rbot, rtop, len);
			rbot = cur;
		}
	}
	return len;
}