[ccan] [PATCH 3/3] memfuncs: Implement memrchr()
Rusty Russell
rusty at rustcorp.com.au
Tue Oct 21 11:28:12 AEDT 2014
David Gibson <david at gibson.dropbear.id.au> writes:
> On Sun, Oct 19, 2014 at 05:00:45PM +0300, Ran Benita wrote:
>> On Sun, Oct 19, 2014 at 02:07:46PM +0200, David Gibson wrote:
>> > The memrchr() function, which works like memchr(), but searches from the
>> > back of the region to the front is implemented in the GNU C library, but
>> > isn't standard.
>> >
>> > This patch adds an implementation of the function to the memfuncs module,
>> > when it's not available in the system C library.
>> >
>> > Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
>> > ---
>> > ccan/memfuncs/memfuncs.c | 14 ++++++++++++++
>> > ccan/memfuncs/memfuncs.h | 4 ++++
>> > ccan/memfuncs/test/run.c | 16 +++++++++++++++-
>> > tools/configurator/configurator.c | 6 ++++++
>> > 4 files changed, 39 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/ccan/memfuncs/memfuncs.c b/ccan/memfuncs/memfuncs.c
>> > index c80b862..2674f41 100644
>> > --- a/ccan/memfuncs/memfuncs.c
>> > +++ b/ccan/memfuncs/memfuncs.c
>> > @@ -25,3 +25,17 @@ void *memmem(const void *haystack, size_t haystacklen,
>> > return NULL;
>> > }
>> > #endif
>> > +
>> > +#if !HAVE_MEMRCHR
>> > +void *memrchr(const void *s, int c, size_t n)
>> > +{
>> > + unsigned char *p = (unsigned char *)s;
>> > + size_t i;
>>
>> This needs to be ssize_t, otherwise the loop doesn't end.
>
> Good point. More importantly, the fact that my testcases did
> terminate indicates that they're not actually testing the local
> implementations :(.
Yes, that's weird. ccanlint's "tests_pass_without_features" *should*
have caught this.
Let me check...
Rusty.
More information about the ccan
mailing list