[ccan] [PATCH 3/3] memfuncs: Implement memrchr()

David Gibson david at gibson.dropbear.id.au
Tue Oct 21 07:36:53 AEDT 2014


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 :(.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20141020/374ce886/attachment.sig>


More information about the ccan mailing list