Is there something similar to bsearch built in, that returns the immediately smaller element if the same element is not present and NULL only if the element is already smaller than all other elements. This would require the user to check if the return value's key is same as the function argument, but it would be very useful in its own right. Thanks.
As far as I can say there is no such function in the standard library. But it should not be to hard to do this on your own or find a library.