[sheepdog] [PATCH] make qsort and bsearch type safe

Liu Yuan namei.unix at gmail.com
Thu May 16 06:51:42 CEST 2013


On 05/16/2013 12:39 PM, MORITA Kazutaka wrote:
> +#define typesafe_qsort(base, nmemb, compar)				\
> +({									\
> +	assert(compar(base, base) == 0);				\
> +	qsort(base, nmemb, sizeof(*(base)), (comparison_fn_t)compar);	\
> +})
> +
> +#define typesafe_bsearch(key, base, nmemb, compar)			\
> +({									\
> +	(void) (key == base);						\
> +	assert(compar(base, base) == 0);				\
> +	bsearch(key, base, nmemb, sizeof(*(base)), (comparison_fn_t)compar); \
> +})

I think xqsort and xbsearch is much more keyboard friendly and uniform
with other xhelpers.

Thanks,
Yuan



More information about the sheepdog mailing list